-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day07Spec.hs
115 lines (113 loc) · 3.73 KB
/
Day07Spec.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
module Day07Spec where
import Common
import qualified Data.Sequence as Seq
import Day05 hiding (main)
import Day07 hiding (main)
import Test.Hspec
main =
hspec $ do
describe "all" $ do
it "part1" $ do
let c =
fromList
[ 3
, 15
, 3
, 16
, 1002
, 16
, 10
, 16
, 1
, 16
, 15
, 15
, 4
, 15
, 99
, 0
, 0
]
tryPhaseSetting c [4, 3, 2, 1, 0] `shouldBe` 43210
let c2 =
fromList
[ 3
, 31
, 3
, 32
, 1002
, 32
, 10
, 32
, 1001
, 31
, -2
, 31
, 1007
, 31
, 0
, 33
, 1002
, 33
, 7
, 33
, 1
, 33
, 31
, 31
, 1
, 32
, 31
, 31
, 4
, 31
, 99
, 0
, 0
, 0
]
tryPhaseSetting c2 [1, 0, 4, 3, 2] `shouldBe` 65210
findMaxOutput c2 `shouldBe` 65210
it "nextOutput" $ do
let c = fromList [3, 0, 4, 0, 4, 6, 99]
let (c', out) = nextOutput 23 c
out `shouldBe` Just 23
let (c'', out2) = nextOutput 23 c'
out2 `shouldBe` Just 99
let (c''', out3) = nextOutput 23 c''
out3 `shouldBe` Nothing
it "part2" $ do
let c =
fromList
[ 3
, 26
, 1001
, 26
, -4
, 26
, 3
, 27
, 1002
, 27
, 2
, 27
, 1
, 27
, 26
, 27
, 4
, 27
, 1001
, 28
, -1
, 28
, 1005
, 28
, 6
, 99
, 0
, 0
, 5
]
tryPhaseSetting2 c [9, 8, 7, 6, 5] `shouldBe` 139629729
findMaxOutput2 c `shouldBe` 139629729