about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-12-06 14:53:44 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-12-06 14:53:44 +0100
commit7b5dad8d4c9d4f91fc13f950ceff75383b75c5c4 (patch)
tree188a490c63b39a560ba4f7056979eaa3eebda7a6
parente9bdceb4c8f0322b4711811ec689f1ea3472a089 (diff)
downloadadventofcode2021-7b5dad8d4c9d4f91fc13f950ceff75383b75c5c4.tar.gz
adventofcode2021-7b5dad8d4c9d4f91fc13f950ceff75383b75c5c4.tar.xz
adventofcode2021-7b5dad8d4c9d4f91fc13f950ceff75383b75c5c4.zip
day05
-rw-r--r--day05500
-rw-r--r--day05.bqn6
-rw-r--r--day05.clj44
3 files changed, 550 insertions, 0 deletions
diff --git a/day05 b/day05
new file mode 100644
index 0000000..324b3b7
--- /dev/null
+++ b/day05
@@ -0,0 +1,500 @@
+260,605 -> 260,124
+308,411 -> 656,63
+570,791 -> 396,617
+622,593 -> 622,240
+944,801 -> 829,916
+310,439 -> 310,676
+448,595 -> 867,176
+293,167 -> 975,849
+375,252 -> 830,707
+679,819 -> 498,819
+58,391 -> 58,653
+674,489 -> 745,489
+296,172 -> 646,522
+63,976 -> 944,976
+471,377 -> 471,17
+172,980 -> 172,136
+942,61 -> 29,974
+238,304 -> 44,498
+961,196 -> 199,196
+219,452 -> 219,87
+40,709 -> 40,132
+657,239 -> 657,860
+95,579 -> 95,522
+740,613 -> 572,445
+71,243 -> 71,861
+313,561 -> 121,753
+775,350 -> 775,271
+872,864 -> 872,942
+677,879 -> 685,879
+456,425 -> 456,227
+719,845 -> 719,245
+543,467 -> 543,446
+254,921 -> 523,921
+792,794 -> 391,393
+247,839 -> 911,839
+645,381 -> 645,39
+297,239 -> 297,358
+106,582 -> 263,739
+269,907 -> 600,907
+41,405 -> 276,405
+765,454 -> 765,570
+587,243 -> 587,193
+945,972 -> 14,41
+896,597 -> 896,338
+564,952 -> 564,83
+533,79 -> 15,597
+367,972 -> 367,243
+280,135 -> 180,135
+140,26 -> 140,757
+646,781 -> 13,148
+245,29 -> 245,436
+482,565 -> 482,327
+608,709 -> 608,687
+379,392 -> 379,98
+400,839 -> 400,484
+531,735 -> 274,735
+771,946 -> 771,850
+724,626 -> 724,983
+359,726 -> 426,726
+665,610 -> 665,342
+119,708 -> 294,708
+398,393 -> 816,811
+810,133 -> 986,133
+640,35 -> 97,578
+376,682 -> 673,682
+394,363 -> 946,363
+755,869 -> 755,898
+252,178 -> 557,178
+798,687 -> 239,687
+171,913 -> 907,177
+432,540 -> 432,751
+127,863 -> 127,117
+618,513 -> 618,348
+908,961 -> 44,97
+944,200 -> 276,868
+388,244 -> 602,30
+686,433 -> 131,988
+413,867 -> 858,422
+873,65 -> 201,737
+66,65 -> 219,65
+354,792 -> 199,637
+198,19 -> 977,798
+372,321 -> 213,321
+938,169 -> 845,76
+798,679 -> 267,679
+833,350 -> 833,275
+764,838 -> 505,838
+590,771 -> 76,257
+89,664 -> 636,117
+955,284 -> 34,284
+152,850 -> 152,816
+772,504 -> 772,969
+527,242 -> 82,242
+699,493 -> 462,256
+592,751 -> 462,881
+61,427 -> 395,427
+144,711 -> 144,611
+483,760 -> 717,760
+616,268 -> 616,82
+542,947 -> 542,44
+396,830 -> 501,725
+589,520 -> 241,868
+397,631 -> 397,533
+87,928 -> 892,928
+789,17 -> 222,584
+639,192 -> 229,192
+617,482 -> 407,692
+197,13 -> 197,153
+786,715 -> 786,42
+634,203 -> 784,203
+370,562 -> 517,415
+726,188 -> 713,188
+859,974 -> 222,337
+584,48 -> 584,519
+28,493 -> 173,638
+252,697 -> 252,503
+810,380 -> 706,380
+367,805 -> 676,496
+266,321 -> 266,527
+327,635 -> 240,548
+108,460 -> 283,460
+309,314 -> 309,599
+653,300 -> 653,13
+327,283 -> 327,596
+597,102 -> 597,374
+646,630 -> 484,792
+215,643 -> 215,202
+227,437 -> 64,437
+768,774 -> 768,587
+703,698 -> 274,698
+849,401 -> 841,401
+235,122 -> 551,122
+446,102 -> 340,208
+749,317 -> 107,959
+94,628 -> 110,612
+25,611 -> 620,16
+989,227 -> 30,227
+894,987 -> 840,987
+24,967 -> 979,12
+659,890 -> 659,571
+255,28 -> 228,28
+598,500 -> 598,447
+804,700 -> 921,700
+45,574 -> 45,154
+112,242 -> 112,402
+77,684 -> 77,691
+975,454 -> 960,469
+24,977 -> 985,16
+924,387 -> 924,177
+815,73 -> 815,656
+687,277 -> 687,100
+273,404 -> 144,533
+511,560 -> 687,560
+248,507 -> 38,507
+671,896 -> 671,866
+750,83 -> 244,589
+408,73 -> 946,611
+627,455 -> 627,299
+48,982 -> 48,795
+371,880 -> 454,963
+766,794 -> 275,303
+199,106 -> 24,281
+461,649 -> 489,649
+966,935 -> 192,161
+675,309 -> 952,32
+389,110 -> 389,119
+182,111 -> 275,111
+10,887 -> 832,65
+643,871 -> 643,488
+282,170 -> 282,65
+11,43 -> 925,957
+19,509 -> 492,36
+80,906 -> 668,318
+582,163 -> 582,153
+556,401 -> 556,116
+853,348 -> 185,348
+989,987 -> 14,12
+209,742 -> 924,27
+970,545 -> 970,364
+195,905 -> 848,252
+86,96 -> 24,96
+142,69 -> 484,69
+984,919 -> 107,42
+406,291 -> 613,291
+859,306 -> 520,306
+563,343 -> 754,343
+434,345 -> 558,345
+498,82 -> 800,384
+641,412 -> 952,412
+614,873 -> 614,706
+956,19 -> 11,964
+486,618 -> 575,707
+32,114 -> 736,818
+699,854 -> 343,854
+645,777 -> 581,777
+607,302 -> 254,302
+495,316 -> 495,587
+47,391 -> 302,391
+901,320 -> 548,320
+112,144 -> 112,218
+780,904 -> 780,582
+814,761 -> 279,761
+15,622 -> 456,622
+986,987 -> 10,11
+13,988 -> 985,16
+413,802 -> 640,802
+118,634 -> 118,771
+34,235 -> 34,976
+154,941 -> 154,195
+115,184 -> 763,832
+381,568 -> 191,568
+460,565 -> 628,565
+217,67 -> 775,67
+375,446 -> 375,585
+593,408 -> 448,408
+564,410 -> 564,567
+921,805 -> 540,424
+794,447 -> 794,485
+892,19 -> 892,618
+811,789 -> 811,923
+36,16 -> 988,968
+431,454 -> 293,592
+598,611 -> 430,779
+760,767 -> 29,767
+347,124 -> 501,124
+851,954 -> 55,158
+698,573 -> 439,573
+78,687 -> 647,118
+181,644 -> 928,644
+393,424 -> 89,424
+210,245 -> 712,747
+654,74 -> 406,322
+29,287 -> 98,287
+307,337 -> 144,337
+696,156 -> 111,156
+86,424 -> 86,299
+148,875 -> 900,123
+918,768 -> 359,209
+826,278 -> 294,810
+572,697 -> 939,697
+984,709 -> 132,709
+311,314 -> 815,314
+713,342 -> 424,53
+220,570 -> 737,570
+335,222 -> 335,344
+483,454 -> 978,949
+32,925 -> 865,92
+936,668 -> 565,668
+520,45 -> 520,931
+920,486 -> 910,476
+787,901 -> 787,450
+613,271 -> 355,13
+859,415 -> 834,415
+144,28 -> 144,850
+121,971 -> 249,971
+458,786 -> 967,786
+282,213 -> 282,587
+925,940 -> 371,940
+100,927 -> 927,927
+979,984 -> 25,30
+583,532 -> 961,910
+986,82 -> 986,436
+382,583 -> 641,842
+973,131 -> 973,697
+558,908 -> 567,917
+807,423 -> 315,423
+49,240 -> 328,240
+723,535 -> 831,535
+714,922 -> 714,765
+303,789 -> 303,972
+85,466 -> 85,391
+306,725 -> 306,322
+398,592 -> 342,592
+689,902 -> 95,308
+421,731 -> 421,396
+12,687 -> 12,902
+412,522 -> 412,158
+535,100 -> 981,546
+198,711 -> 198,91
+287,196 -> 719,628
+350,144 -> 931,144
+497,800 -> 497,278
+68,919 -> 68,876
+199,519 -> 199,284
+796,321 -> 245,321
+827,640 -> 254,67
+674,842 -> 473,842
+11,227 -> 203,227
+295,462 -> 10,747
+869,574 -> 583,288
+427,761 -> 303,885
+593,760 -> 373,760
+415,238 -> 415,641
+694,556 -> 721,556
+127,672 -> 716,83
+698,769 -> 156,227
+325,198 -> 826,198
+64,23 -> 986,945
+338,942 -> 338,597
+41,835 -> 852,835
+497,332 -> 569,404
+166,734 -> 747,153
+623,820 -> 623,637
+49,238 -> 921,238
+958,829 -> 174,45
+485,732 -> 79,732
+413,765 -> 537,889
+340,204 -> 340,158
+986,434 -> 710,434
+104,90 -> 915,90
+332,112 -> 332,760
+731,692 -> 490,933
+258,913 -> 311,913
+271,890 -> 717,890
+451,898 -> 425,872
+722,564 -> 768,564
+316,630 -> 316,60
+712,220 -> 712,658
+532,202 -> 387,57
+794,231 -> 44,981
+587,409 -> 587,535
+907,195 -> 907,760
+233,776 -> 963,46
+267,665 -> 267,148
+303,183 -> 952,183
+908,469 -> 908,725
+518,976 -> 753,976
+845,636 -> 531,636
+774,225 -> 51,948
+914,797 -> 632,797
+853,343 -> 542,654
+174,637 -> 567,637
+193,220 -> 622,220
+90,229 -> 14,229
+284,745 -> 82,543
+795,174 -> 795,210
+524,507 -> 265,507
+371,953 -> 371,844
+906,402 -> 123,402
+192,881 -> 192,549
+519,299 -> 726,92
+986,989 -> 986,706
+774,55 -> 493,55
+702,290 -> 165,290
+200,650 -> 683,167
+367,603 -> 321,603
+193,31 -> 704,542
+630,885 -> 703,885
+330,966 -> 330,285
+960,306 -> 960,820
+281,62 -> 281,25
+12,542 -> 12,627
+669,505 -> 237,937
+237,174 -> 200,211
+66,424 -> 585,943
+92,115 -> 881,904
+559,282 -> 920,282
+67,815 -> 67,47
+199,985 -> 140,926
+70,25 -> 979,934
+694,555 -> 27,555
+622,644 -> 159,644
+582,983 -> 256,983
+230,712 -> 315,712
+976,877 -> 190,91
+680,957 -> 680,245
+257,767 -> 257,315
+943,380 -> 943,412
+320,95 -> 320,774
+843,644 -> 292,93
+416,342 -> 416,605
+302,682 -> 302,925
+79,107 -> 885,913
+18,980 -> 973,25
+379,947 -> 379,963
+11,987 -> 987,11
+634,749 -> 634,310
+875,295 -> 718,295
+818,904 -> 471,557
+963,803 -> 963,133
+640,870 -> 939,571
+54,423 -> 547,916
+880,121 -> 880,332
+671,275 -> 31,275
+820,559 -> 820,609
+45,924 -> 936,33
+233,314 -> 136,217
+680,634 -> 680,883
+780,217 -> 531,217
+477,304 -> 477,166
+904,725 -> 904,472
+307,326 -> 850,869
+875,435 -> 341,969
+714,382 -> 544,552
+981,934 -> 197,934
+621,439 -> 621,786
+414,902 -> 414,238
+821,546 -> 243,546
+313,753 -> 301,753
+510,566 -> 510,593
+38,601 -> 210,429
+344,411 -> 344,490
+653,970 -> 653,698
+32,155 -> 746,155
+814,701 -> 26,701
+928,141 -> 430,141
+890,804 -> 972,804
+374,183 -> 374,387
+821,327 -> 907,413
+180,27 -> 180,813
+848,194 -> 848,496
+905,589 -> 618,302
+633,114 -> 659,114
+546,613 -> 217,942
+191,336 -> 344,336
+265,442 -> 834,442
+801,388 -> 801,339
+399,212 -> 731,212
+649,559 -> 649,112
+783,108 -> 178,108
+113,670 -> 948,670
+524,596 -> 257,329
+371,397 -> 371,784
+344,465 -> 344,819
+307,234 -> 307,453
+984,964 -> 31,11
+466,743 -> 841,743
+185,722 -> 745,722
+845,36 -> 147,734
+77,21 -> 982,926
+415,252 -> 69,252
+420,976 -> 420,526
+104,694 -> 104,645
+806,197 -> 29,974
+278,101 -> 494,101
+598,664 -> 17,83
+175,708 -> 175,764
+888,392 -> 270,392
+141,564 -> 141,672
+507,255 -> 956,255
+519,36 -> 89,36
+662,526 -> 661,526
+642,970 -> 642,725
+684,79 -> 237,526
+352,166 -> 583,166
+335,366 -> 400,366
+568,627 -> 789,406
+115,257 -> 115,925
+803,110 -> 803,643
+694,189 -> 114,769
+441,344 -> 217,568
+207,838 -> 207,163
+832,975 -> 832,384
+340,178 -> 340,729
+251,550 -> 268,533
+324,962 -> 396,962
+649,875 -> 649,692
+87,939 -> 984,42
+947,966 -> 34,53
+368,555 -> 777,964
+24,31 -> 977,984
+168,471 -> 168,740
+689,717 -> 689,256
+836,78 -> 105,809
+538,542 -> 963,117
+247,779 -> 247,331
+198,968 -> 717,968
+85,61 -> 85,444
+410,439 -> 410,482
+678,940 -> 29,291
+893,907 -> 270,284
+355,493 -> 355,439
+89,902 -> 809,902
+73,507 -> 73,180
+686,405 -> 740,351
+939,372 -> 354,957
+774,388 -> 774,402
+424,720 -> 542,720
+495,570 -> 246,570
+583,904 -> 583,680
+816,458 -> 275,458
+206,654 -> 633,654
+70,94 -> 70,919
+826,538 -> 821,538
+837,451 -> 370,918
+421,667 -> 902,186
+415,863 -> 942,863
+13,364 -> 13,958
+181,687 -> 150,718
+265,698 -> 931,32
+10,17 -> 967,974
+507,323 -> 507,324
+429,21 -> 429,533
+843,351 -> 843,812
+380,148 -> 631,399
+313,762 -> 198,647
+814,183 -> 493,183
+923,456 -> 874,407
+857,100 -> 10,947
+893,115 -> 25,983
diff --git a/day05.bqn b/day05.bqn
new file mode 100644
index 0000000..3cb624a
--- /dev/null
+++ b/day05.bqn
@@ -0,0 +1,6 @@
+str←•Import"bqn-libs/strings.bqn"
+d ← {•BQN¨∾{"," str.Split 𝕩}¨ " -> " str.Split 𝕩}¨ •FLines"day05"
+
+Line ← {s<⊸+(<×e-s)×↕1+⌈´|(e←2↓𝕩)-(s←2↑𝕩)}
+•Out +´1=⊒∾Line¨d /˜ 0=×´˘(>d)-2⌽˘>d
+•Out +´1=⊒∾Line¨d
diff --git a/day05.clj b/day05.clj
new file mode 100644
index 0000000..6e5185b
--- /dev/null
+++ b/day05.clj
@@ -0,0 +1,44 @@
+(ns org.vuxu.aoc2021.day05
+  (:require [clojure.string :as str]))
+
+(def data
+  (->> (slurp "day05")
+       (str/split-lines)
+       (map #(str/split % #",| -> "))
+       (map (partial map parse-long))))
+
+(use 'criterium.core)
+
+(def part1
+  (->> data
+       (filter (fn [[x1 y1 x2 y2]]
+                 (or (= x1 x2) (= y1 y2))))
+       (mapcat (fn [[x1 y1 x2 y2]]
+                 (for [x (range (min x1 x2) (inc (max x1 x2)))
+                       y (range (min y1 y2) (inc (max y1 y2)))]
+                   [x y])))
+       frequencies
+       vals
+       (filter #(< 1 %))
+       count))
+;; => 5092
+
+(defn points [[x1 y1 x2 y2]]
+  (let [dx (Long/signum (- x2 x1))
+        dy (Long/signum (- y2 y1))]
+    (loop [x x1
+           y y1
+           r []]
+      (if (and (= x2 x)
+               (= y2 y))
+        (conj r [x y])
+        (recur (+ x dx) (+ y dy) (conj r [x y]))))))
+
+(def part2
+  (->> data
+       (mapcat points)
+       frequencies
+       vals
+       (filter #(< 1 %))
+       count))
+;; => 20484