Last active
December 1, 2019 12:33
-
-
Save giuliohome/31b734e7d14c795103748cd3e583ebf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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