Skip to content

Instantly share code, notes, and snippets.

@giuliohome
Last active December 1, 2019 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuliohome/31b734e7d14c795103748cd3e583ebf1 to your computer and use it in GitHub Desktop.
Save giuliohome/31b734e7d14c795103748cd3e583ebf1 to your computer and use it in GitHub Desktop.
open System
open System.IO
let readInts (path:string) =
[|
use sw = new StreamReader (path)
while (not sw.EndOfStream) do
yield sw.ReadLine() |> Int32.Parse
|]
let swapf f x y = f y x
let fuel =
swapf (/) 3
>> swapf (-) 2
let fullFuel =
Seq.unfold
(fuel >> function
| x when x <= 0 -> None
| x -> Some (x, x))
>> Seq.sum
[<EntryPoint>]
let main argv =
let input = readInts @"C:\dev\FSharp\AoC2019\Day1\input_part2.txt"
let fuels : int [] =
Array.map fullFuel input
fuels
|> Array.sum
|> printfn "Answer: %d"
Console.ReadKey() |> ignore
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment