day1
This commit is contained in:
parent
c626cdfa96
commit
b338b3c2ca
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
main = do
|
||||||
|
content <- getContents
|
||||||
|
putStrLn (show $ foldl getOp 0 (lines content))
|
||||||
|
|
||||||
|
getOp :: Int -> String -> Int
|
||||||
|
getOp acc number = acc + (math (read number)) + getFuel 0 (math(read number))
|
||||||
|
|
||||||
|
getFuel :: Int -> Int -> Int
|
||||||
|
getFuel acc fuel = do
|
||||||
|
if (math fuel) > 0
|
||||||
|
then acc + (math fuel) + getFuel acc (math fuel)
|
||||||
|
else
|
||||||
|
acc
|
||||||
|
|
||||||
|
math :: Int -> Int
|
||||||
|
math input = ((input `div` 3) - 2)
|
Loading…
Reference in New Issue
Block a user