Skip to content

Commit bcf6601

Browse files
committed
Solution to day #01
1 parent c07461b commit bcf6601

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed

01/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
01
2+
01.exe
3+
01.o
4+
01.hi

01/01.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
numbers :: String -> [Int]
2+
numbers numbersString = map read (lines numbersString)
3+
4+
pairs :: [a] -> [[a]]
5+
pairs values = [[x,y] | x <- values, y <- values]
6+
7+
triples :: [a] -> [[a]]
8+
triples values = [[x,y,z] | x <- values, y <- values, z <- values]
9+
10+
sumsUpTo2020 :: [Int] -> Bool
11+
sumsUpTo2020 numbers = sum numbers == 2020
12+
13+
productOfValuesSummingUpTo2020 :: [[Int]] -> Int
14+
productOfValuesSummingUpTo2020 values = product (head(filter sumsUpTo2020 values))
15+
16+
17+
main = do
18+
expensesReport <- readFile "./expense-report.txt"
19+
let expenses = numbers expensesReport
20+
print (productOfValuesSummingUpTo2020 (pairs expenses))
21+
print (productOfValuesSummingUpTo2020 (triples expenses))

01/expense-report.txt

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
1313
2+
1968
3+
1334
4+
1566
5+
820
6+
1435
7+
1369
8+
1230
9+
1383
10+
1816
11+
1396
12+
1974
13+
1911
14+
1989
15+
1824
16+
1430
17+
1709
18+
1204
19+
1792
20+
1800
21+
1703
22+
2009
23+
1467
24+
1400
25+
1315
26+
1985
27+
1598
28+
1215
29+
1574
30+
1770
31+
1870
32+
1352
33+
1544
34+
1339
35+
188
36+
1347
37+
1986
38+
2003
39+
1538
40+
1839
41+
1688
42+
1350
43+
1191
44+
1961
45+
1578
46+
1946
47+
1548
48+
1975
49+
1745
50+
1631
51+
1390
52+
1811
53+
1586
54+
1409
55+
247
56+
1600
57+
1565
58+
1929
59+
1854
60+
1602
61+
1773
62+
1815
63+
1887
64+
1689
65+
1266
66+
1573
67+
1534
68+
1939
69+
1909
70+
1273
71+
1386
72+
1713
73+
1268
74+
1611
75+
1348
76+
1478
77+
1857
78+
1916
79+
1113
80+
936
81+
1603
82+
1716
83+
1875
84+
1855
85+
1834
86+
1701
87+
1279
88+
1346
89+
1503
90+
1797
91+
1287
92+
1447
93+
1475
94+
1950
95+
1614
96+
1261
97+
1442
98+
1299
99+
1465
100+
896
101+
1481
102+
1804
103+
1931
104+
1849
105+
1675
106+
1726
107+
355
108+
1485
109+
1343
110+
1697
111+
1735
112+
1858
113+
1205
114+
1345
115+
1281
116+
253
117+
1808
118+
1557
119+
1964
120+
1771
121+
1891
122+
1583
123+
1896
124+
1398
125+
1930
126+
1258
127+
1338
128+
1208
129+
1328
130+
1493
131+
1963
132+
1374
133+
1212
134+
1223
135+
1501
136+
2004
137+
1591
138+
1954
139+
115
140+
1972
141+
1814
142+
1643
143+
1270
144+
1349
145+
1297
146+
1399
147+
1969
148+
1237
149+
1228
150+
1379
151+
1779
152+
1765
153+
1427
154+
1464
155+
1247
156+
1967
157+
1577
158+
1719
159+
1559
160+
1274
161+
1879
162+
1504
163+
1732
164+
1277
165+
1758
166+
1721
167+
1936
168+
1605
169+
1358
170+
1505
171+
1411
172+
1823
173+
1576
174+
1682
175+
1439
176+
1901
177+
1940
178+
1760
179+
1414
180+
1193
181+
1900
182+
1990
183+
1781
184+
1801
185+
1239
186+
1729
187+
1360
188+
1780
189+
1848
190+
1468
191+
1484
192+
1280
193+
1278
194+
1851
195+
1903
196+
1894
197+
1731
198+
1451
199+
549
200+
1570

0 commit comments

Comments
 (0)