alan rewite day1 haskell
This commit is contained in:
20
day1/day1.hs
20
day1/day1.hs
File diff suppressed because one or more lines are too long
16
day1/day1_p1.hs
Normal file
16
day1/day1_p1.hs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import Data.List
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
input <- readFile "input.txt"
|
||||||
|
print . count . map read $ words input
|
||||||
|
|
||||||
|
count :: [Int] -> Int
|
||||||
|
count (x:xs) = count_f x xs
|
||||||
|
|
||||||
|
count_f :: Int -> [Int] -> Int
|
||||||
|
count_f _ [] = 0
|
||||||
|
count_f nb (x:xs)
|
||||||
|
| x > nb = 1 + count_f x xs
|
||||||
|
| otherwise = count_f x xs
|
||||||
|
|
||||||
20
day1/day1_p2.hs
Normal file
20
day1/day1_p2.hs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import Data.List
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
input <- readFile "input.txt"
|
||||||
|
print . count . average . map read $ words input
|
||||||
|
|
||||||
|
average :: [Int] -> [Int]
|
||||||
|
average (x:y:[]) = []
|
||||||
|
average (x:y:z:xs) = x+y+z:average (y:z:xs)
|
||||||
|
|
||||||
|
count :: [Int] -> Int
|
||||||
|
count (x:xs) = count_f x xs
|
||||||
|
|
||||||
|
count_f :: Int -> [Int] -> Int
|
||||||
|
count_f _ [] = 0
|
||||||
|
count_f nb (x:xs)
|
||||||
|
| x > nb = 1 + count_f x xs
|
||||||
|
| otherwise = count_f x xs
|
||||||
|
|
||||||
2001
day1/input.txt
Normal file
2001
day1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
10
day1/test.txt
Normal file
10
day1/test.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
199
|
||||||
|
200
|
||||||
|
208
|
||||||
|
210
|
||||||
|
200
|
||||||
|
207
|
||||||
|
240
|
||||||
|
269
|
||||||
|
260
|
||||||
|
263
|
||||||
Reference in New Issue
Block a user