Skip to content

Instantly share code, notes, and snippets.

@hayleigh-dot-dev
Last active December 1, 2019 14:50
Show Gist options
  • Save hayleigh-dot-dev/8b8a225dd2923798a24a4cef1ab9c72e to your computer and use it in GitHub Desktop.
Save hayleigh-dot-dev/8b8a225dd2923798a24a4cef1ab9c72e to your computer and use it in GitHub Desktop.
module AdventOfCode.Day01 exposing
( part1
, part2
)
-- Imports ---------------------------------------------------------------------
import Utils
-- Functions -------------------------------------------------------------------
--
calculateFuel : Int -> Int
calculateFuel =
Utils.flip (//) 3 >> Utils.flip (-) 2
--
calculateFuelRecursively : Int -> Int
calculateFuelRecursively =
calculateFuel >> \x -> if x <= 6 then x else x + calculateFuelRecursively x
--
solveWith : ( Int -> Int ) -> String -> Float
solveWith solver input =
String.lines input
|> List.filterMap ( String.toInt >> Maybe.map solver )
|> List.sum
|> Basics.toFloat
-- Solvers ---------------------------------------------------------------------
part1 : String -> Float
part1 =
solveWith calculateFuel
part2 : String -> Float
part2 =
solveWith calculateFuelRecursively
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment