-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10.hs
65 lines (57 loc) · 1.45 KB
/
10.hs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Lib
import Debug.Trace
import Data.List (sort)
dummyAdapters = [ 16
, 10
, 15
, 5
, 1
, 11
, 7
, 19
, 6
, 12
, 4 ]
dummyAdapters2 = [ 28
, 33
, 18
, 42
, 31
, 14
, 46
, 20
, 48
, 47
, 24
, 23
, 49
, 45
, 19
, 38
, 39
, 11
, 1
, 32
, 25
, 35
, 8
, 17
, 7
, 9
, 4
, 2
, 34
, 10
, 3 ]
counts l = map (\x -> (x, length $ filter (==x) l)) [0..3]
calcResult l = snd . head $ scanr (\a (b,l) -> (a ,(b-a):l)) (maximum l + 3,[]) $ sort $ 0:l
main = do
let dummyResult = calcResult dummyAdapters
print $ counts dummyResult
print $ counts $ calcResult dummyAdapters2
contents <- readFile "10.input"
let adapters = map (read @Int) $ lines contents
print $ counts $ calcResult adapters