This commit is contained in:
opfez 2021-12-01 08:47:08 +01:00
commit 3dd4e18c01
4 changed files with 2027 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*/first.o
*/first.hi
*/second.o
*/second.hi
*/first
*/second

9
day1/first.hs Normal file
View File

@ -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

2000
day1/input Normal file

File diff suppressed because it is too large Load Diff

12
day1/second.hs Normal file
View File

@ -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