day 1
This commit is contained in:
commit
3dd4e18c01
|
@ -0,0 +1,6 @@
|
|||
*/first.o
|
||||
*/first.hi
|
||||
*/second.o
|
||||
*/second.hi
|
||||
*/first
|
||||
*/second
|
|
@ -0,0 +1,9 @@
|
|||
loop :: Int -> [Int] -> Int -> Int
|
||||
loop _ [] acc = acc
|
||||
loop prev (curr:rest) acc
|
||||
| prev < curr = loop curr rest (acc + 1)
|
||||
| otherwise = loop curr rest acc
|
||||
|
||||
main = interact $ solution . getInput
|
||||
where solution input = show $ loop (head input) (tail input) 0
|
||||
getInput = map read . words
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,12 @@
|
|||
loop :: Int -> [Int] -> Int -> Int
|
||||
loop _ [] acc = acc
|
||||
loop prev (one:two:three:rest) acc
|
||||
| prev < sum = loop sum (two:three:rest) (acc + 1)
|
||||
| otherwise = loop sum (two:three:rest) acc
|
||||
where sum = one + two + three
|
||||
-- ignore last numbers that don't fit into a three number window
|
||||
loop _ _ acc = acc
|
||||
|
||||
main = interact $ solution . getInput
|
||||
where solution input = show $ loop (head input) (tail input) 0
|
||||
getInput = map read . words
|
Loading…
Reference in New Issue