-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathday10.hs
More file actions
33 lines (27 loc) · 847 Bytes
/
day10.hs
File metadata and controls
33 lines (27 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Data.List
import System.Environment
convert :: String -> [Int]
convert = map read . lines
absdiff :: [Int] -> [Int]
absdiff lst = zipWith (diff_num lst) [0 .. ] lst
diff_num :: [Int] -> Int -> Int -> Int
diff_num diff idx number
| first = number
| otherwise = number - diff !! (idx -1)
where first = idx == 0
ordering :: [Int] -> Int
ordering lst = product filtered
where filtered = map possibilities $ filter (1 `elem` ) $ group lst
possibilities :: [Int] -> Int
possibilities lst
| l < 4 = 2 ^ (l - 1)
| l == 4 = 7
where l = length lst
main = do
args <- getArgs
content <- readFile (head $ args)
let diffs = absdiff (sort $ convert content) ++ [3]
let diff1 = length $ filter (== 1) diffs
let diff3 = length $ filter (== 3) diffs
print $ diff1 * diff3
print $ ordering diffs