Last active
December 1, 2019 14:50
-
-
Save hayleigh-dot-dev/8b8a225dd2923798a24a4cef1ab9c72e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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