diff options
-rw-r--r-- | aoc.cabal | 6 | ||||
-rw-r--r-- | default.nix | 3 | ||||
-rw-r--r-- | execs/Day08.hs | 4 | ||||
-rw-r--r-- | execs/Day09.hs | 35 | ||||
-rw-r--r-- | input/09 | 1000 | ||||
-rw-r--r-- | input/09sample | 20 | ||||
-rw-r--r-- | lib/Utils.hs | 5 |
7 files changed, 1070 insertions, 3 deletions
@@ -69,3 +69,9 @@ executable Day08 | |||
69 | build-depends: base, aoc, containers | 69 | build-depends: base, aoc, containers |
70 | default-language: Haskell2010 | 70 | default-language: Haskell2010 |
71 | hs-source-dirs: execs | 71 | hs-source-dirs: execs |
72 | |||
73 | executable Day09 | ||
74 | main-is: Day09.hs | ||
75 | build-depends: base, aoc, containers, parsec | ||
76 | default-language: Haskell2010 | ||
77 | hs-source-dirs: execs | ||
diff --git a/default.nix b/default.nix index 64861a5..78e9f1f 100644 --- a/default.nix +++ b/default.nix | |||
@@ -3,8 +3,9 @@ mkDerivation { | |||
3 | pname = "aoc"; | 3 | pname = "aoc"; |
4 | version = "0.1.0.0"; | 4 | version = "0.1.0.0"; |
5 | src = ./.; | 5 | src = ./.; |
6 | isLibrary = false; | 6 | isLibrary = true; |
7 | isExecutable = true; | 7 | isExecutable = true; |
8 | libraryHaskellDepends = [ base ]; | ||
8 | executableHaskellDepends = [ base containers parsec ]; | 9 | executableHaskellDepends = [ base containers parsec ]; |
9 | license = "unknown"; | 10 | license = "unknown"; |
10 | hydraPlatforms = stdenv.lib.platforms.none; | 11 | hydraPlatforms = stdenv.lib.platforms.none; |
diff --git a/execs/Day08.hs b/execs/Day08.hs index 7d3fce8..6546990 100644 --- a/execs/Day08.hs +++ b/execs/Day08.hs | |||
@@ -40,6 +40,6 @@ genAll (acc:rest) = map (acc:) $ genAll rest | |||
40 | main :: IO () | 40 | main :: IO () |
41 | main = do | 41 | main = do |
42 | n <- map (parseLine . words) . lines <$> readFile "input/08" | 42 | n <- map (parseLine . words) . lines <$> readFile "input/08" |
43 | let solve1 = run 0 0 Set.empty . Map.fromList . zip [0..] | 43 | let solve1 = run 0 0 mempty . Map.fromList . zip [0..] |
44 | print $ solve1 n | 44 | print $ solve1 n |
45 | print $ solve1 $ head $ filter (doesEnd 0 0 Set.empty . Map.fromList . zip [0..]) $ genAll n | 45 | print $ solve1 $ head $ filter (doesEnd 0 0 mempty . Map.fromList . zip [0..]) $ genAll n |
diff --git a/execs/Day09.hs b/execs/Day09.hs new file mode 100644 index 0000000..e2e5fd4 --- /dev/null +++ b/execs/Day09.hs | |||
@@ -0,0 +1,35 @@ | |||
1 | |||
2 | module Main where | ||
3 | |||
4 | import Utils | ||
5 | import Data.List (inits, tails, find) | ||
6 | import Data.Bifunctor | ||
7 | |||
8 | parseLine :: String -> Int | ||
9 | parseLine = read | ||
10 | |||
11 | doCheck :: [Int] -> Int -> Bool | ||
12 | doCheck preamble target = target `elem` p | ||
13 | where p = [x + y | x <- preamble, y <- preamble, x /= y] | ||
14 | |||
15 | checkAll :: [Int] -> [Int] -> [(Int, Bool)] | ||
16 | checkAll preamble [x] = [(x, doCheck preamble x)] | ||
17 | checkAll preamble@(p:ps) (x:xs) = (x, doCheck preamble x) : checkAll (ps++[x]) xs | ||
18 | |||
19 | |||
20 | findWeakness :: [[Int]] -> Int -> Int | ||
21 | findWeakness subs target = mn + mx | ||
22 | where Just t = find ((== target) . sum) subs | ||
23 | mn = minimum t | ||
24 | mx = maximum t | ||
25 | |||
26 | main :: IO () | ||
27 | main = do | ||
28 | n <- map parseLine . lines <$> readFile "input/09" | ||
29 | let preambleLen = 25 | ||
30 | Just (target, _) = find (not . snd) | ||
31 | $ uncurry checkAll | ||
32 | $ bimap (take preambleLen) (drop preambleLen) | ||
33 | $ (,) n n | ||
34 | print target | ||
35 | print $ findWeakness (sublists n) target | ||
diff --git a/input/09 b/input/09 new file mode 100644 index 0000000..e8a2fe7 --- /dev/null +++ b/input/09 | |||
@@ -0,0 +1,1000 @@ | |||
1 | 29 | ||
2 | 44 | ||
3 | 11 | ||
4 | 5 | ||
5 | 42 | ||
6 | 8 | ||
7 | 17 | ||
8 | 23 | ||
9 | 18 | ||
10 | 16 | ||
11 | 50 | ||
12 | 47 | ||
13 | 21 | ||
14 | 3 | ||
15 | 25 | ||
16 | 28 | ||
17 | 36 | ||
18 | 34 | ||
19 | 48 | ||
20 | 30 | ||
21 | 32 | ||
22 | 40 | ||
23 | 22 | ||
24 | 19 | ||
25 | 41 | ||
26 | 13 | ||
27 | 56 | ||
28 | 14 | ||
29 | 11 | ||
30 | 20 | ||
31 | 39 | ||
32 | 43 | ||
33 | 17 | ||
34 | 64 | ||
35 | 57 | ||
36 | 66 | ||
37 | 31 | ||
38 | 16 | ||
39 | 106 | ||
40 | 27 | ||
41 | 79 | ||
42 | 25 | ||
43 | 36 | ||
44 | 24 | ||
45 | 46 | ||
46 | 38 | ||
47 | 28 | ||
48 | 33 | ||
49 | 92 | ||
50 | 29 | ||
51 | 30 | ||
52 | 34 | ||
53 | 89 | ||
54 | 35 | ||
55 | 53 | ||
56 | 83 | ||
57 | 42 | ||
58 | 40 | ||
59 | 137 | ||
60 | 41 | ||
61 | 50 | ||
62 | 43 | ||
63 | 68 | ||
64 | 49 | ||
65 | 69 | ||
66 | 52 | ||
67 | 79 | ||
68 | 60 | ||
69 | 54 | ||
70 | 62 | ||
71 | 165 | ||
72 | 57 | ||
73 | 87 | ||
74 | 102 | ||
75 | 95 | ||
76 | 110 | ||
77 | 114 | ||
78 | 75 | ||
79 | 76 | ||
80 | 239 | ||
81 | 81 | ||
82 | 94 | ||
83 | 176 | ||
84 | 84 | ||
85 | 163 | ||
86 | 92 | ||
87 | 119 | ||
88 | 173 | ||
89 | 143 | ||
90 | 167 | ||
91 | 106 | ||
92 | 111 | ||
93 | 116 | ||
94 | 197 | ||
95 | 132 | ||
96 | 133 | ||
97 | 194 | ||
98 | 151 | ||
99 | 156 | ||
100 | 157 | ||
101 | 159 | ||
102 | 160 | ||
103 | 313 | ||
104 | 165 | ||
105 | 175 | ||
106 | 249 | ||
107 | 178 | ||
108 | 240 | ||
109 | 176 | ||
110 | 269 | ||
111 | 198 | ||
112 | 217 | ||
113 | 286 | ||
114 | 310 | ||
115 | 227 | ||
116 | 424 | ||
117 | 289 | ||
118 | 273 | ||
119 | 434 | ||
120 | 265 | ||
121 | 393 | ||
122 | 332 | ||
123 | 415 | ||
124 | 337 | ||
125 | 444 | ||
126 | 530 | ||
127 | 325 | ||
128 | 340 | ||
129 | 341 | ||
130 | 351 | ||
131 | 354 | ||
132 | 451 | ||
133 | 374 | ||
134 | 403 | ||
135 | 492 | ||
136 | 649 | ||
137 | 922 | ||
138 | 500 | ||
139 | 537 | ||
140 | 516 | ||
141 | 538 | ||
142 | 554 | ||
143 | 590 | ||
144 | 639 | ||
145 | 597 | ||
146 | 825 | ||
147 | 867 | ||
148 | 662 | ||
149 | 665 | ||
150 | 666 | ||
151 | 841 | ||
152 | 676 | ||
153 | 1113 | ||
154 | 715 | ||
155 | 705 | ||
156 | 957 | ||
157 | 777 | ||
158 | 1242 | ||
159 | 1134 | ||
160 | 1016 | ||
161 | 1037 | ||
162 | 1038 | ||
163 | 1328 | ||
164 | 1054 | ||
165 | 1155 | ||
166 | 1092 | ||
167 | 1144 | ||
168 | 1187 | ||
169 | 1236 | ||
170 | 1312 | ||
171 | 1327 | ||
172 | 1799 | ||
173 | 1623 | ||
174 | 1331 | ||
175 | 1342 | ||
176 | 1381 | ||
177 | 2518 | ||
178 | 1420 | ||
179 | 1482 | ||
180 | 1662 | ||
181 | 2049 | ||
182 | 1814 | ||
183 | 2419 | ||
184 | 2146 | ||
185 | 2404 | ||
186 | 3382 | ||
187 | 2342 | ||
188 | 2209 | ||
189 | 2247 | ||
190 | 3141 | ||
191 | 2236 | ||
192 | 3296 | ||
193 | 2563 | ||
194 | 2567 | ||
195 | 2654 | ||
196 | 4727 | ||
197 | 2673 | ||
198 | 2712 | ||
199 | 2863 | ||
200 | 2723 | ||
201 | 2801 | ||
202 | 4050 | ||
203 | 3469 | ||
204 | 3144 | ||
205 | 6270 | ||
206 | 5287 | ||
207 | 3960 | ||
208 | 4456 | ||
209 | 4355 | ||
210 | 4445 | ||
211 | 4483 | ||
212 | 4551 | ||
213 | 5236 | ||
214 | 7099 | ||
215 | 5099 | ||
216 | 5217 | ||
217 | 9278 | ||
218 | 6142 | ||
219 | 8568 | ||
220 | 5327 | ||
221 | 5385 | ||
222 | 5396 | ||
223 | 8540 | ||
224 | 5524 | ||
225 | 5867 | ||
226 | 5945 | ||
227 | 8996 | ||
228 | 9196 | ||
229 | 7104 | ||
230 | 8315 | ||
231 | 12316 | ||
232 | 8405 | ||
233 | 9681 | ||
234 | 8800 | ||
235 | 8928 | ||
236 | 9034 | ||
237 | 11341 | ||
238 | 10316 | ||
239 | 12203 | ||
240 | 10909 | ||
241 | 10544 | ||
242 | 10712 | ||
243 | 10723 | ||
244 | 10781 | ||
245 | 10851 | ||
246 | 10920 | ||
247 | 11263 | ||
248 | 14979 | ||
249 | 11391 | ||
250 | 11812 | ||
251 | 18609 | ||
252 | 18445 | ||
253 | 15419 | ||
254 | 17827 | ||
255 | 17205 | ||
256 | 17333 | ||
257 | 17439 | ||
258 | 17962 | ||
259 | 17834 | ||
260 | 19244 | ||
261 | 19350 | ||
262 | 20860 | ||
263 | 21028 | ||
264 | 31447 | ||
265 | 29956 | ||
266 | 35796 | ||
267 | 21504 | ||
268 | 30270 | ||
269 | 22732 | ||
270 | 23203 | ||
271 | 22183 | ||
272 | 35273 | ||
273 | 47289 | ||
274 | 26810 | ||
275 | 27231 | ||
276 | 32858 | ||
277 | 40566 | ||
278 | 53718 | ||
279 | 41976 | ||
280 | 34538 | ||
281 | 37206 | ||
282 | 35401 | ||
283 | 38694 | ||
284 | 53888 | ||
285 | 47838 | ||
286 | 40854 | ||
287 | 41888 | ||
288 | 53159 | ||
289 | 54041 | ||
290 | 78108 | ||
291 | 82830 | ||
292 | 43687 | ||
293 | 44915 | ||
294 | 57741 | ||
295 | 58604 | ||
296 | 48993 | ||
297 | 59668 | ||
298 | 60089 | ||
299 | 61348 | ||
300 | 86576 | ||
301 | 83531 | ||
302 | 69939 | ||
303 | 71744 | ||
304 | 73232 | ||
305 | 72607 | ||
306 | 74095 | ||
307 | 98362 | ||
308 | 91853 | ||
309 | 82742 | ||
310 | 127430 | ||
311 | 84541 | ||
312 | 85575 | ||
313 | 93908 | ||
314 | 103519 | ||
315 | 88602 | ||
316 | 92680 | ||
317 | 101428 | ||
318 | 106263 | ||
319 | 106734 | ||
320 | 107597 | ||
321 | 108661 | ||
322 | 121016 | ||
323 | 135443 | ||
324 | 134580 | ||
325 | 175178 | ||
326 | 141683 | ||
327 | 171344 | ||
328 | 144351 | ||
329 | 145839 | ||
330 | 181104 | ||
331 | 158636 | ||
332 | 193172 | ||
333 | 250489 | ||
334 | 167283 | ||
335 | 173143 | ||
336 | 170116 | ||
337 | 174177 | ||
338 | 245779 | ||
339 | 313122 | ||
340 | 200277 | ||
341 | 194108 | ||
342 | 207691 | ||
343 | 311799 | ||
344 | 214331 | ||
345 | 216258 | ||
346 | 295193 | ||
347 | 255596 | ||
348 | 356014 | ||
349 | 278931 | ||
350 | 286034 | ||
351 | 287522 | ||
352 | 374974 | ||
353 | 290190 | ||
354 | 304475 | ||
355 | 325919 | ||
356 | 328752 | ||
357 | 340426 | ||
358 | 361391 | ||
359 | 341460 | ||
360 | 343259 | ||
361 | 462037 | ||
362 | 374454 | ||
363 | 401799 | ||
364 | 394385 | ||
365 | 407968 | ||
366 | 408439 | ||
367 | 422022 | ||
368 | 430589 | ||
369 | 501853 | ||
370 | 506448 | ||
371 | 534527 | ||
372 | 628982 | ||
373 | 700893 | ||
374 | 564965 | ||
375 | 683685 | ||
376 | 695961 | ||
377 | 594665 | ||
378 | 1223647 | ||
379 | 776253 | ||
380 | 836491 | ||
381 | 669178 | ||
382 | 681886 | ||
383 | 772049 | ||
384 | 1351064 | ||
385 | 717713 | ||
386 | 824974 | ||
387 | 768839 | ||
388 | 989050 | ||
389 | 802353 | ||
390 | 816407 | ||
391 | 830461 | ||
392 | 852611 | ||
393 | 932442 | ||
394 | 1036380 | ||
395 | 1571192 | ||
396 | 1248650 | ||
397 | 1295558 | ||
398 | 1379646 | ||
399 | 1159630 | ||
400 | 1263843 | ||
401 | 1276551 | ||
402 | 1312378 | ||
403 | 1386891 | ||
404 | 1399599 | ||
405 | 2560242 | ||
406 | 2097911 | ||
407 | 1450725 | ||
408 | 1540888 | ||
409 | 1520066 | ||
410 | 1542687 | ||
411 | 1593813 | ||
412 | 1585246 | ||
413 | 2763103 | ||
414 | 2435979 | ||
415 | 1646868 | ||
416 | 1683072 | ||
417 | 1785053 | ||
418 | 1968822 | ||
419 | 2821433 | ||
420 | 2436181 | ||
421 | 2408280 | ||
422 | 2423473 | ||
423 | 2539276 | ||
424 | 2472008 | ||
425 | 2995450 | ||
426 | 2711977 | ||
427 | 2929578 | ||
428 | 3691724 | ||
429 | 2850324 | ||
430 | 2970791 | ||
431 | 2991613 | ||
432 | 5257614 | ||
433 | 3060954 | ||
434 | 3276885 | ||
435 | 4444137 | ||
436 | 3179059 | ||
437 | 3232114 | ||
438 | 3468125 | ||
439 | 6229190 | ||
440 | 5183985 | ||
441 | 5655587 | ||
442 | 3753875 | ||
443 | 4908189 | ||
444 | 6007401 | ||
445 | 4831753 | ||
446 | 4880288 | ||
447 | 9920914 | ||
448 | 5011284 | ||
449 | 5322332 | ||
450 | 5562301 | ||
451 | 10563776 | ||
452 | 5779902 | ||
453 | 5821115 | ||
454 | 5841937 | ||
455 | 14752667 | ||
456 | 6932934 | ||
457 | 9843037 | ||
458 | 6240013 | ||
459 | 6745010 | ||
460 | 8585628 | ||
461 | 8937860 | ||
462 | 9076207 | ||
463 | 7222000 | ||
464 | 8634163 | ||
465 | 9316176 | ||
466 | 9739942 | ||
467 | 10442589 | ||
468 | 10470490 | ||
469 | 9891572 | ||
470 | 9712041 | ||
471 | 12774871 | ||
472 | 10333616 | ||
473 | 10573585 | ||
474 | 16824506 | ||
475 | 11342203 | ||
476 | 14427565 | ||
477 | 16682602 | ||
478 | 12061128 | ||
479 | 13063937 | ||
480 | 15330638 | ||
481 | 12985023 | ||
482 | 13462013 | ||
483 | 13967010 | ||
484 | 15379173 | ||
485 | 17664589 | ||
486 | 15856163 | ||
487 | 16538176 | ||
488 | 16934041 | ||
489 | 25747735 | ||
490 | 20465157 | ||
491 | 19451983 | ||
492 | 21773169 | ||
493 | 19603613 | ||
494 | 20045657 | ||
495 | 20285626 | ||
496 | 20907201 | ||
497 | 38597675 | ||
498 | 21915788 | ||
499 | 25046151 | ||
500 | 23403331 | ||
501 | 25125065 | ||
502 | 25523141 | ||
503 | 26028138 | ||
504 | 28364196 | ||
505 | 42331206 | ||
506 | 26447036 | ||
507 | 27429023 | ||
508 | 35424830 | ||
509 | 39649270 | ||
510 | 32394339 | ||
511 | 36141789 | ||
512 | 33472217 | ||
513 | 36386024 | ||
514 | 47816179 | ||
515 | 42855314 | ||
516 | 58057577 | ||
517 | 39889239 | ||
518 | 51970177 | ||
519 | 82504584 | ||
520 | 41192827 | ||
521 | 48336224 | ||
522 | 59500355 | ||
523 | 47040853 | ||
524 | 48926472 | ||
525 | 48528396 | ||
526 | 54392334 | ||
527 | 53876059 | ||
528 | 79241338 | ||
529 | 76275263 | ||
530 | 134332840 | ||
531 | 76617657 | ||
532 | 62853853 | ||
533 | 65866556 | ||
534 | 73587166 | ||
535 | 68780363 | ||
536 | 83182642 | ||
537 | 93163004 | ||
538 | 111933636 | ||
539 | 87705418 | ||
540 | 81082066 | ||
541 | 86930092 | ||
542 | 91859416 | ||
543 | 88233680 | ||
544 | 122513638 | ||
545 | 135274533 | ||
546 | 162423980 | ||
547 | 207920006 | ||
548 | 111382249 | ||
549 | 102802531 | ||
550 | 131711038 | ||
551 | 108268393 | ||
552 | 116729912 | ||
553 | 246266476 | ||
554 | 142367529 | ||
555 | 185367491 | ||
556 | 131634216 | ||
557 | 134646919 | ||
558 | 370343986 | ||
559 | 149862429 | ||
560 | 195965535 | ||
561 | 168012158 | ||
562 | 204963592 | ||
563 | 144381670 | ||
564 | 258130822 | ||
565 | 169315746 | ||
566 | 175163772 | ||
567 | 180093096 | ||
568 | 284742070 | ||
569 | 279394407 | ||
570 | 211070924 | ||
571 | 214184780 | ||
572 | 219532443 | ||
573 | 224998305 | ||
574 | 234436747 | ||
575 | 239902609 | ||
576 | 434604499 | ||
577 | 248364128 | ||
578 | 519178817 | ||
579 | 519297016 | ||
580 | 281496645 | ||
581 | 266281135 | ||
582 | 279028589 | ||
583 | 294244099 | ||
584 | 344479518 | ||
585 | 312393828 | ||
586 | 380127364 | ||
587 | 563770659 | ||
588 | 363914113 | ||
589 | 519643290 | ||
590 | 388848189 | ||
591 | 399625539 | ||
592 | 453969190 | ||
593 | 425255704 | ||
594 | 430603367 | ||
595 | 433717223 | ||
596 | 908491479 | ||
597 | 444530748 | ||
598 | 459435052 | ||
599 | 678967495 | ||
600 | 683092288 | ||
601 | 591422417 | ||
602 | 733327707 | ||
603 | 1252970997 | ||
604 | 712745812 | ||
605 | 1472262138 | ||
606 | 545309724 | ||
607 | 573272688 | ||
608 | 701242017 | ||
609 | 708393631 | ||
610 | 1499913896 | ||
611 | 833342762 | ||
612 | 752762302 | ||
613 | 844156287 | ||
614 | 788473728 | ||
615 | 1556902099 | ||
616 | 853594729 | ||
617 | 855859071 | ||
618 | 893152275 | ||
619 | 864320590 | ||
620 | 1752647766 | ||
621 | 1004744776 | ||
622 | 903965800 | ||
623 | 1032707740 | ||
624 | 1118582412 | ||
625 | 1501219540 | ||
626 | 1424765179 | ||
627 | 1745453552 | ||
628 | 1326034990 | ||
629 | 1246551741 | ||
630 | 1253703355 | ||
631 | 1274514705 | ||
632 | 1454004319 | ||
633 | 1534584779 | ||
634 | 1461155933 | ||
635 | 1541236030 | ||
636 | 1596918589 | ||
637 | 1644332799 | ||
638 | 1632630015 | ||
639 | 2445201830 | ||
640 | 1709453800 | ||
641 | 1717915319 | ||
642 | 2995240349 | ||
643 | 2871230178 | ||
644 | 2151290152 | ||
645 | 1908710576 | ||
646 | 1936673540 | ||
647 | 2178480505 | ||
648 | 2707707674 | ||
649 | 2365134153 | ||
650 | 2500255096 | ||
651 | 2600549695 | ||
652 | 2521066446 | ||
653 | 4672356598 | ||
654 | 2528218060 | ||
655 | 2714859288 | ||
656 | 4405814957 | ||
657 | 4424313088 | ||
658 | 4304626263 | ||
659 | 4074587953 | ||
660 | 4244882494 | ||
661 | 5100804791 | ||
662 | 3896395824 | ||
663 | 3342083815 | ||
664 | 3427369119 | ||
665 | 3618164376 | ||
666 | 3845384116 | ||
667 | 7692752329 | ||
668 | 4060000728 | ||
669 | 4087191081 | ||
670 | 4115154045 | ||
671 | 4886200599 | ||
672 | 4543614658 | ||
673 | 5079993441 | ||
674 | 4865389249 | ||
675 | 6424613884 | ||
676 | 8568752422 | ||
677 | 5049284506 | ||
678 | 8269697204 | ||
679 | 5243077348 | ||
680 | 6142228407 | ||
681 | 13669557213 | ||
682 | 7501957072 | ||
683 | 6769452934 | ||
684 | 6960248191 | ||
685 | 8360036539 | ||
686 | 18749550654 | ||
687 | 7272753235 | ||
688 | 11779943410 | ||
689 | 7045533495 | ||
690 | 7463548492 | ||
691 | 8388998774 | ||
692 | 16081751103 | ||
693 | 24441787642 | ||
694 | 8202345126 | ||
695 | 8658768703 | ||
696 | 9409003907 | ||
697 | 20625365761 | ||
698 | 12911681341 | ||
699 | 10292361854 | ||
700 | 12012530282 | ||
701 | 14652081255 | ||
702 | 19811785620 | ||
703 | 11385305755 | ||
704 | 12203325539 | ||
705 | 13644185479 | ||
706 | 14509081987 | ||
707 | 18658058990 | ||
708 | 14318286730 | ||
709 | 14005781686 | ||
710 | 14736301727 | ||
711 | 15247878621 | ||
712 | 21114026467 | ||
713 | 15665893618 | ||
714 | 33100556345 | ||
715 | 15852547266 | ||
716 | 16591343900 | ||
717 | 27962472209 | ||
718 | 16861113829 | ||
719 | 22304892136 | ||
720 | 18067772610 | ||
721 | 19701365761 | ||
722 | 23588631294 | ||
723 | 28159559962 | ||
724 | 25391087441 | ||
725 | 23397836037 | ||
726 | 36779920085 | ||
727 | 25029491234 | ||
728 | 25894387742 | ||
729 | 26939627266 | ||
730 | 27649967165 | ||
731 | 28324068416 | ||
732 | 28742083413 | ||
733 | 29054588457 | ||
734 | 44511080994 | ||
735 | 37552770757 | ||
736 | 50628960552 | ||
737 | 46391841026 | ||
738 | 32713661095 | ||
739 | 32443891166 | ||
740 | 45020673791 | ||
741 | 45717739775 | ||
742 | 40258949866 | ||
743 | 34928886439 | ||
744 | 58326722476 | ||
745 | 37769138371 | ||
746 | 43099201798 | ||
747 | 48427327271 | ||
748 | 48788923478 | ||
749 | 53353559650 | ||
750 | 49292223779 | ||
751 | 77481915728 | ||
752 | 50923878976 | ||
753 | 61037729511 | ||
754 | 54589594431 | ||
755 | 56392050578 | ||
756 | 57066151829 | ||
757 | 71841285211 | ||
758 | 70213029537 | ||
759 | 70266431852 | ||
760 | 84160979397 | ||
761 | 65157552261 | ||
762 | 67372777605 | ||
763 | 67642547534 | ||
764 | 72698024810 | ||
765 | 75187836305 | ||
766 | 104277438626 | ||
767 | 115392874305 | ||
768 | 105141915976 | ||
769 | 87061362150 | ||
770 | 86196465642 | ||
771 | 91526529069 | ||
772 | 97216250749 | ||
773 | 103881818210 | ||
774 | 100216102755 | ||
775 | 150179940538 | ||
776 | 111655746260 | ||
777 | 105513473407 | ||
778 | 204769534969 | ||
779 | 126658482430 | ||
780 | 113458202407 | ||
781 | 122223704090 | ||
782 | 142107717063 | ||
783 | 156409495179 | ||
784 | 137855577071 | ||
785 | 132530329866 | ||
786 | 179298293794 | ||
787 | 158899306674 | ||
788 | 154703909684 | ||
789 | 147885861115 | ||
790 | 190473904268 | ||
791 | 197040002476 | ||
792 | 206919403374 | ||
793 | 173257827792 | ||
794 | 177722994711 | ||
795 | 183412716391 | ||
796 | 235681906497 | ||
797 | 217340020617 | ||
798 | 350980822503 | ||
799 | 217169219667 | ||
800 | 247621190470 | ||
801 | 328824965927 | ||
802 | 227737177497 | ||
803 | 301007023737 | ||
804 | 240116684837 | ||
805 | 361135711102 | ||
806 | 380151520336 | ||
807 | 292559486755 | ||
808 | 287234239550 | ||
809 | 328329481339 | ||
810 | 280416190981 | ||
811 | 327184154909 | ||
812 | 302589770799 | ||
813 | 395063015328 | ||
814 | 321143688907 | ||
815 | 356670544183 | ||
816 | 475798591334 | ||
817 | 390332119765 | ||
818 | 390427047459 | ||
819 | 394892214378 | ||
820 | 573744836156 | ||
821 | 434509240284 | ||
822 | 444906397164 | ||
823 | 504403459217 | ||
824 | 530326948296 | ||
825 | 581423214718 | ||
826 | 620888968094 | ||
827 | 716206704235 | ||
828 | 520532875818 | ||
829 | 527350924387 | ||
830 | 755652929191 | ||
831 | 567650430531 | ||
832 | 682126453928 | ||
833 | 1151215916390 | ||
834 | 1057221806052 | ||
835 | 675479206309 | ||
836 | 1043390859144 | ||
837 | 659260314982 | ||
838 | 1095001354918 | ||
839 | 677814233090 | ||
840 | 1065811326074 | ||
841 | 835238516929 | ||
842 | 1208141181386 | ||
843 | 1077018668306 | ||
844 | 829401454662 | ||
845 | 879415637448 | ||
846 | 938912699501 | ||
847 | 1551445221164 | ||
848 | 1752497874615 | ||
849 | 1047883800205 | ||
850 | 1088183306349 | ||
851 | 1141421843912 | ||
852 | 1635068566639 | ||
853 | 1179793190800 | ||
854 | 1341386768910 | ||
855 | 1488661769644 | ||
856 | 1226910745513 | ||
857 | 1747443621331 | ||
858 | 1334739521291 | ||
859 | 1337074548072 | ||
860 | 2482808612822 | ||
861 | 1494498831911 | ||
862 | 1743625559164 | ||
863 | 1507215687752 | ||
864 | 1513052750019 | ||
865 | 1923421823278 | ||
866 | 2015931367807 | ||
867 | 1708817092110 | ||
868 | 1768314154163 | ||
869 | 1818328336949 | ||
870 | 1927299437653 | ||
871 | 2273652220792 | ||
872 | 2136067106554 | ||
873 | 3650999934446 | ||
874 | 2189305644117 | ||
875 | 2429570075259 | ||
876 | 2476161365203 | ||
877 | 2976455335549 | ||
878 | 2568297514423 | ||
879 | 2561650266804 | ||
880 | 3695613591816 | ||
881 | 4991220342063 | ||
882 | 2671814069363 | ||
883 | 2847792271310 | ||
884 | 2831573379983 | ||
885 | 3001714519663 | ||
886 | 3007551581930 | ||
887 | 3216032779862 | ||
888 | 5808028715532 | ||
889 | 5233464336167 | ||
890 | 3850721260931 | ||
891 | 3477131246273 | ||
892 | 3586642491112 | ||
893 | 4091980557741 | ||
894 | 4775091708963 | ||
895 | 4063366544207 | ||
896 | 4325372750671 | ||
897 | 4565637181813 | ||
898 | 5147975434566 | ||
899 | 4618875719376 | ||
900 | 9473348185237 | ||
901 | 5323953636513 | ||
902 | 5129947781227 | ||
903 | 5416089785733 | ||
904 | 5679365651293 | ||
905 | 8314489311192 | ||
906 | 5839124961913 | ||
907 | 5503387449346 | ||
908 | 7977740052537 | ||
909 | 5833287899646 | ||
910 | 6693164026135 | ||
911 | 8625106680839 | ||
912 | 6802675270974 | ||
913 | 9766851153942 | ||
914 | 7063773737385 | ||
915 | 7327852507204 | ||
916 | 7540497790480 | ||
917 | 7650009035319 | ||
918 | 15642341818396 | ||
919 | 9942829355889 | ||
920 | 12688473225046 | ||
921 | 14868350297684 | ||
922 | 10034965505109 | ||
923 | 9748823500603 | ||
924 | 10122263168722 | ||
925 | 10453901417740 | ||
926 | 12017117662648 | ||
927 | 11182753100639 | ||
928 | 11512653550939 | ||
929 | 11342512411259 | ||
930 | 11336675348992 | ||
931 | 12526451925781 | ||
932 | 12897061637031 | ||
933 | 17726563553140 | ||
934 | 18877173139472 | ||
935 | 13495839297109 | ||
936 | 13866449008359 | ||
937 | 14130527778178 | ||
938 | 14977861542523 | ||
939 | 17362818012313 | ||
940 | 15190506825799 | ||
941 | 23809278364248 | ||
942 | 17398832535922 | ||
943 | 32917070378939 | ||
944 | 19691652856492 | ||
945 | 45605543603985 | ||
946 | 21790576766732 | ||
947 | 24409715187970 | ||
948 | 19871086669325 | ||
949 | 20576164586462 | ||
950 | 23353793011640 | ||
951 | 22519428449631 | ||
952 | 31207762018317 | ||
953 | 32218104782273 | ||
954 | 22679187760251 | ||
955 | 26763510645390 | ||
956 | 33473226223493 | ||
957 | 41080356564780 | ||
958 | 28473700839632 | ||
959 | 27362288305468 | ||
960 | 27626367075287 | ||
961 | 27996976786537 | ||
962 | 63599785014411 | ||
963 | 42390515118956 | ||
964 | 60215081568810 | ||
965 | 32589339361721 | ||
966 | 37090485392414 | ||
967 | 37269919205247 | ||
968 | 39562739525817 | ||
969 | 42366741353194 | ||
970 | 40447251255787 | ||
971 | 50264277606364 | ||
972 | 61099593298780 | ||
973 | 58981615427663 | ||
974 | 54125798950858 | ||
975 | 45873221461271 | ||
976 | 61063040201353 | ||
977 | 49442698405641 | ||
978 | 61946927063125 | ||
979 | 50041476065719 | ||
980 | 54988655380755 | ||
981 | 104431353786396 | ||
982 | 64632207510715 | ||
983 | 105079458766502 | ||
984 | 55359265092005 | ||
985 | 55623343861824 | ||
986 | 67559716312354 | ||
987 | 69859258566968 | ||
988 | 72152078887538 | ||
989 | 89889949661428 | ||
990 | 69679824754135 | ||
991 | 144878605042183 | ||
992 | 95315919866912 | ||
993 | 80009990781604 | ||
994 | 82813992608981 | ||
995 | 152162069669142 | ||
996 | 101496565323095 | ||
997 | 104854836888934 | ||
998 | 95914697526990 | ||
999 | 99484174471360 | ||
1000 | 100861876842026 | ||
diff --git a/input/09sample b/input/09sample new file mode 100644 index 0000000..28d66e4 --- /dev/null +++ b/input/09sample | |||
@@ -0,0 +1,20 @@ | |||
1 | 35 | ||
2 | 20 | ||
3 | 15 | ||
4 | 25 | ||
5 | 47 | ||
6 | 40 | ||
7 | 62 | ||
8 | 55 | ||
9 | 65 | ||
10 | 95 | ||
11 | 102 | ||
12 | 117 | ||
13 | 150 | ||
14 | 182 | ||
15 | 127 | ||
16 | 219 | ||
17 | 299 | ||
18 | 277 | ||
19 | 309 | ||
20 | 576 | ||
diff --git a/lib/Utils.hs b/lib/Utils.hs index 4319714..89b1bd3 100644 --- a/lib/Utils.hs +++ b/lib/Utils.hs | |||
@@ -5,11 +5,13 @@ module Utils ( binaryToInt | |||
5 | , bet | 5 | , bet |
6 | , (&+) | 6 | , (&+) |
7 | , howMany | 7 | , howMany |
8 | , sublists | ||
8 | ) where | 9 | ) where |
9 | 10 | ||
10 | import Data.Char (digitToInt) | 11 | import Data.Char (digitToInt) |
11 | import Control.Monad | 12 | import Control.Monad |
12 | import Data.Either | 13 | import Data.Either |
14 | import Data.List (inits, tails) | ||
13 | 15 | ||
14 | 16 | ||
15 | binaryToInt :: String -> Int | 17 | binaryToInt :: String -> Int |
@@ -34,3 +36,6 @@ bet k (l, u) = k >= l && k <= u | |||
34 | 36 | ||
35 | howMany :: (a -> Bool) -> [a] -> Int | 37 | howMany :: (a -> Bool) -> [a] -> Int |
36 | howMany predicate = length . filter predicate | 38 | howMany predicate = length . filter predicate |
39 | |||
40 | sublists :: [a] -> [[a]] | ||
41 | sublists = concatMap inits . tails | ||