Skip to content

Commit 0e6ff1e

Browse files
committed
Day02
1 parent f1358cf commit 0e6ff1e

File tree

2 files changed

+1026
-0
lines changed

2 files changed

+1026
-0
lines changed

Day02.hs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Day02 where
2+
3+
import Control.Applicative
4+
import Data.List
5+
import System.IO
6+
7+
slurp :: IO [[Int]]
8+
slurp = map (map read . words) <$> lines <$> readFile "input-02"
9+
10+
safe xs = all small diffs
11+
where diffs = zipWith (-) (tail xs) xs
12+
sign = signum (head diffs)
13+
small d = signum d == sign && abs d >= 1 && abs d <= 3
14+
15+
part1 = length . filter safe
16+
17+
deletions [] = []
18+
deletions (x:xs) = xs:map (x:) (deletions xs)
19+
20+
damped xs = any safe (deletions xs)
21+
22+
part2 = length . filter damped
23+
24+
main = do
25+
--print =<< part1 <$> slurp
26+
print =<< part2 <$> slurp

0 commit comments

Comments
 (0)