Compare commits

...

10 Commits

Author SHA1 Message Date
Zoé Cassiopée Gauthier
661db710c6 Day 25 2021-12-25 15:58:26 -05:00
Zoé Cassiopée Gauthier
aedd3a237b Day 24 (abandoned) 2021-12-25 15:58:26 -05:00
Zoé Cassiopée Gauthier
a36181d01b Day 23 (abandoned) 2021-12-25 15:58:26 -05:00
Zoé Cassiopée Gauthier
96e7d52445 Day 22 2021-12-23 14:28:27 -05:00
Zoé Cassiopée Gauthier
5572ea973e Day 21 2021-12-21 22:32:52 -05:00
Zoé Cassiopée Gauthier
e37e81188d Day 20 2021-12-20 21:41:01 -05:00
Zoé Cassiopée Gauthier
8384ef7a95 Day 19 (abandoned) 2021-12-20 17:19:59 -05:00
Zoé Cassiopée Gauthier
dea378d80e Day 18 (abandoned) 2021-12-19 07:31:36 -05:00
Zoé Cassiopée Gauthier
1d57712afa Day 17 2021-12-17 21:45:00 -05:00
Zoé Cassiopée Gauthier
155d13568a Day 16 2021-12-17 14:38:20 -05:00
20 changed files with 3517 additions and 0 deletions

View File

@ -3,6 +3,10 @@ name = "advent2021"
version = "0.1.0"
edition = "2021"
[profile.release]
lto = true
debug = 1
[[bin]]
name = "day1"
path = "src/day1.rs"
@ -62,3 +66,43 @@ path = "src/day14.rs"
[[bin]]
name = "day15"
path = "src/day15.rs"
[[bin]]
name = "day16"
path = "src/day16.rs"
[[bin]]
name = "day17"
path = "src/day17.rs"
[[bin]]
name = "day18"
path = "src/day18.rs"
[[bin]]
name = "day19"
path = "src/day19.rs"
[[bin]]
name = "day20"
path = "src/day20.rs"
[[bin]]
name = "day21"
path = "src/day21.rs"
[[bin]]
name = "day22"
path = "src/day22.rs"
[[bin]]
name = "day23"
path = "src/day23.rs"
[[bin]]
name = "day24"
path = "src/day24.rs"
[[bin]]
name = "day25"
path = "src/day25.rs"

1
inputs/day16.txt Normal file
View File

@ -0,0 +1 @@
20546C8802538E136091C1802689BCD7DA45948D319D1B100747A009C97696E8B4ABFCA6AB8F4F26C401964A6271C80F802D392C01CEDDCE6E5CB829802F600A00021B14E34C361006E0AC418BB2CA6800BE4599BB6A73507002A52BEEB14D201802F600849E64D3369D37C74100866785B3D0ADFD8E601E5EB9DE2366D93ECB8B040142CB8ACE07CCB5CF34CA89380410B6134CE6FEF104A2B200243396976A00401A45004313D68435DBDDDA61CE6428C01491AEBF0C7E580AE00CCC401B86514216880370EE3443D2013DF003750004361343D88800084C4C8B116A679018300740010C8571BA32080350DA0D42800043A3044189AE0174B314D76E1F3ACF3BDAE3EE7298FF134002EF9DBCD0644127E3CAE7FCBA9A80393544F9A927C973DF1A500965A5CEA94C4DDA5658B94C6C3002A798A629CF21280532BAB4F4C7271E45EE6E71D8143A9BC7948804AB94D1D6006AC200EC1E8A10C00010985316A35C3620061E641644D661A4C012993E99208FC60097802F28F528F738606008CA47205400814C89CC8890064D400AB4BE0A66F2BF253E73AE8401424A7BFB16C0037E06CE0641E0013B08010A8930CE2B980351161DC3730066274188B020054A5E16965940057895ADEB5BF56A635ADE2354191D70566273A6F5B078266008D8022200D46E8291C4401A8CF0CE33CEDE55E9F9802BA00B4BD44A5EA2D10CC00B40316800BAE1003580A6D6026F00090E50024007C9500258068850035C00A4012ED8040B400D71002AF500284009700226336CA4980471D655E25D4650888023AB00525CAE5CBA5E428600BE003993778CB4732996E9887AE3F311C291004BD37517C0041E780A7808802AF8C1C00D0CDBE4ACAD69B3B004E13BDF23CAE7368C9F62448F64546008E0034F3720192A67AD9254917454200DCE801C99ADF182575BBAACAC7F8580

100
inputs/day18.txt Normal file
View File

@ -0,0 +1,100 @@
[[[[7,1],[0,0]],[6,[8,2]]],[8,[3,8]]]
[[[3,6],[9,4]],[[[5,9],5],[8,0]]]
[[[2,2],2],[1,[[1,6],7]]]
[[[[0,9],7],[[3,2],8]],[6,[7,9]]]
[[[[4,1],6],[[7,6],[2,2]]],[[[1,1],9],4]]
[[[8,[3,7]],3],[[4,4],[[9,1],[3,5]]]]
[[4,[8,2]],[1,[0,5]]]
[8,[8,7]]
[[[[2,2],7],[3,[4,5]]],[[4,6],[[2,5],4]]]
[[[5,5],[[5,1],3]],[[2,[8,2]],[[6,9],[1,5]]]]
[0,7]
[[[[5,1],3],[8,[5,3]]],7]
[[5,[2,[0,6]]],[[[5,5],2],[9,[8,0]]]]
[[[[3,4],2],0],4]
[[[[5,3],[2,7]],6],[[4,0],[9,[7,2]]]]
[[[3,[2,5]],[3,3]],7]
[[[[5,1],1],[4,8]],[[5,[8,3]],2]]
[[4,[[8,1],[8,5]]],[[[4,1],0],6]]
[[[5,5],[5,9]],[0,[[6,8],[0,1]]]]
[4,[[[7,9],4],0]]
[[[[0,1],7],[[3,6],5]],[8,[5,[6,1]]]]
[[[7,7],[8,0]],[6,[8,[7,9]]]]
[[[9,2],1],6]
[[[4,4],[2,[5,0]]],[[[2,6],6],[5,[4,3]]]]
[[2,[[4,7],5]],1]
[[8,7],[[[2,0],7],[1,[0,3]]]]
[[9,[[9,3],[9,5]]],[[8,7],[[4,1],[6,5]]]]
[[3,4],[[9,4],5]]
[[5,[[8,3],5]],1]
[[0,[[9,0],[3,2]]],[2,[7,[5,1]]]]
[[9,[[9,5],[8,6]]],[[4,4],[[3,8],[1,6]]]]
[[[1,[5,2]],9],[[4,6],[3,[8,0]]]]
[[1,7],[[1,7],9]]
[[[[3,4],3],[[7,5],[9,1]]],[[[5,0],[3,0]],[[7,9],6]]]
[[[7,2],[[1,0],[5,6]]],[[[3,7],[8,9]],6]]
[[[[1,1],1],[[8,6],[9,8]]],[[[1,8],4],[8,9]]]
[[[8,9],0],3]
[[[1,7],[1,[3,9]]],[6,[0,[8,5]]]]
[[0,5],[6,5]]
[[[[6,8],[4,5]],[[7,4],6]],[[3,6],5]]
[[8,[[0,9],8]],[9,[7,[7,9]]]]
[0,[[[7,1],2],[[0,4],4]]]
[[0,[[9,1],5]],[1,4]]
[3,4]
[[[9,3],[1,3]],[[[4,8],3],[[1,3],[9,0]]]]
[[[[5,1],7],[[9,2],8]],[[[6,8],[5,4]],[0,1]]]
[8,[[1,[3,0]],[[7,9],4]]]
[[[6,4],[[2,9],[9,0]]],[7,[[0,0],3]]]
[[3,[[9,6],6]],2]
[[5,[[3,1],[7,5]]],[[[6,7],9],[[4,6],[5,2]]]]
[[[4,[6,5]],8],[[6,[8,0]],[[9,3],3]]]
[[[[4,9],[2,8]],9],[[[5,0],0],[[3,4],[2,8]]]]
[[3,[7,1]],[9,[[1,8],7]]]
[[9,1],[0,[[0,7],[7,1]]]]
[[7,[0,[7,6]]],[[[5,3],1],[6,[4,5]]]]
[8,[[[2,1],[6,9]],[[3,3],[4,6]]]]
[0,[7,[3,0]]]
[[[[1,6],3],[5,[8,0]]],[[[6,6],7],1]]
[[[7,[8,3]],3],[[[2,8],5],[0,[9,5]]]]
[[[[5,1],4],[[1,2],1]],7]
[[[3,[7,5]],7],3]
[[9,[6,[1,1]]],[[[4,1],[2,2]],[[9,5],[7,7]]]]
[2,7]
[[[9,[8,6]],[[9,0],[6,5]]],[[[6,7],5],[[7,7],[2,3]]]]
[[[0,[6,4]],2],[4,[7,[7,5]]]]
[[[[6,1],[9,1]],[[6,1],9]],[[2,6],0]]
[[0,[[1,8],[3,5]]],[4,[[8,2],[4,2]]]]
[[[[9,3],[4,2]],2],[[[2,1],[7,1]],[4,8]]]
[[[3,[0,2]],3],8]
[[[4,[4,9]],9],[[[4,4],5],9]]
[[[[8,2],7],9],[[[1,0],[3,8]],[[7,7],0]]]
[[[3,2],[9,7]],[[9,[8,2]],[[5,5],3]]]
[[[7,[3,1]],[[8,3],1]],[[[8,6],[7,0]],4]]
[[9,[[9,1],5]],[[4,[1,1]],2]]
[[[[7,4],[0,3]],7],[8,[6,[3,3]]]]
[5,5]
[[6,7],[1,[7,[8,1]]]]
[[1,[0,4]],7]
[[[4,0],[[0,1],[2,2]]],[9,[[9,9],[3,0]]]]
[[[6,0],[[8,6],3]],[[5,1],[[8,1],[2,7]]]]
[[[[8,3],7],5],[9,[[5,1],8]]]
[[[[4,0],[5,2]],[[0,0],7]],2]
[[[[0,1],6],2],[[8,2],6]]
[[[[2,4],1],[[6,7],9]],[[[1,6],9],3]]
[[5,5],[[8,[7,7]],[5,8]]]
[[6,[[9,2],[9,7]]],[[[8,5],[4,4]],7]]
[[[9,[7,7]],[6,0]],[7,[[8,7],[1,2]]]]
[[7,[6,2]],[[9,[5,2]],[1,4]]]
[[[7,[5,9]],[[3,9],[4,5]]],[0,6]]
[[9,[8,[2,2]]],[[9,7],[1,1]]]
[[[[2,3],4],[[4,8],9]],[[9,[8,6]],[[0,9],0]]]
[[0,[[9,3],0]],[8,8]]
[[[[2,9],6],[[2,8],9]],[[[0,5],6],[[6,1],7]]]
[[9,[[8,3],[5,8]]],[[7,[3,0]],3]]
[[[4,[4,2]],0],1]
[[[[9,6],[5,8]],[6,2]],[[[8,0],[7,0]],[[5,6],4]]]
[[[8,0],[[4,3],[7,4]]],[[3,[7,9]],[[7,3],6]]]
[[3,[5,[0,3]]],[5,4]]
[[[[1,2],[6,3]],1],[[7,[5,2]],[[8,8],7]]]
[[4,[[8,0],[7,1]]],[[8,[8,0]],[[1,5],3]]]

718
inputs/day19.txt Normal file
View File

@ -0,0 +1,718 @@
--- scanner 0 ---
65,91,116
-514,-323,679
-810,416,687
-670,417,-446
557,770,781
893,-705,-874
769,-603,624
-615,-434,763
866,-777,-839
-884,416,506
666,-551,609
-830,402,-478
714,394,-419
-848,390,535
-723,-356,-598
-884,-326,-497
715,782,804
717,-686,714
661,494,-310
835,-669,-705
-647,-375,698
26,-64,-42
540,729,799
-807,445,-371
-764,-418,-429
632,440,-457
--- scanner 1 ---
623,554,-341
630,-553,-714
694,536,-542
-687,464,-705
-844,532,-645
813,-586,674
-564,576,348
567,-517,-838
756,-671,678
-507,-620,398
-386,-393,-497
-542,-435,-486
620,-612,-772
-77,-1,-31
-457,-467,-531
-596,439,327
828,-606,643
-710,447,340
40,114,47
-512,-705,462
505,928,649
762,555,-401
-636,-638,498
446,804,725
-781,626,-743
565,793,665
--- scanner 2 ---
-396,-811,-616
717,488,380
-552,-346,451
441,-784,-675
-398,-811,-479
404,488,-883
-708,298,-722
468,-673,-592
-540,-745,-557
427,-767,-608
-568,825,585
787,-461,442
488,383,-838
44,17,-60
-645,820,598
750,360,417
629,-453,480
518,616,-826
689,-502,492
-584,770,737
-721,485,-662
-678,358,-768
708,420,516
-638,-442,511
-576,-495,459
--- scanner 3 ---
-586,-450,-590
-727,576,-754
26,-50,57
296,660,742
420,723,706
362,713,647
-628,-549,-574
637,-293,866
603,-364,792
325,-570,-316
-782,511,-717
331,-669,-307
557,937,-229
-629,-741,646
-706,407,542
-82,47,164
417,908,-244
-650,-601,769
-821,503,-650
-654,397,723
648,-449,824
-627,-512,-662
-643,-726,893
534,839,-306
-588,406,593
449,-506,-292
--- scanner 4 ---
-629,-448,-538
-451,559,699
12,137,65
734,-533,479
701,437,-739
665,758,756
-142,50,-4
746,542,-823
455,-619,-759
538,-730,-786
-821,-517,693
-579,-407,-440
-554,414,-477
-749,-476,755
633,713,841
-617,-399,-598
-475,435,635
487,-519,464
610,-540,604
-517,542,-510
707,747,912
-653,474,-519
-466,441,536
689,670,-709
471,-713,-800
-733,-518,656
--- scanner 5 ---
-350,-557,-558
534,-303,-707
-36,79,-85
-474,-620,-594
-657,467,-508
438,792,658
422,773,820
600,-294,-577
596,704,-531
589,829,-407
-543,854,491
382,821,740
-702,552,-476
-847,-613,513
-646,-684,495
-787,-752,514
652,-304,-758
-445,791,585
-483,697,423
483,-527,472
-416,-610,-653
550,-452,548
382,-471,503
575,844,-654
-691,396,-434
--- scanner 6 ---
665,-388,856
-902,331,695
-747,-602,710
401,-727,-532
-842,376,680
396,-780,-707
591,553,-658
694,-414,892
-827,-571,691
502,377,655
576,605,-761
-512,-437,-661
-813,512,-738
437,436,623
419,-768,-549
-734,-410,733
-9,60,-48
-531,-487,-869
-615,-446,-791
486,688,-709
513,-414,818
-712,333,698
-671,498,-758
-819,380,-777
521,325,522
--- scanner 7 ---
-757,981,603
338,-318,715
-552,-640,560
661,-339,-711
-790,870,490
754,439,319
673,-316,-553
380,611,-391
-660,-511,-602
-624,-591,635
-627,-510,499
373,-256,727
-619,893,-522
-845,963,415
596,507,377
330,592,-599
-795,-406,-551
693,563,421
-605,751,-502
-133,-1,-57
-712,-496,-499
339,695,-469
620,-321,-728
405,-288,517
-487,899,-483
--- scanner 8 ---
-575,-817,237
-795,503,280
-784,347,-758
548,860,627
743,-729,-870
426,515,-910
-166,-12,-31
574,849,545
663,-777,-910
581,-748,-854
-484,-785,-703
-604,-843,273
-731,-800,-717
-756,-817,311
377,-816,451
-654,338,-692
409,-831,291
-768,365,283
302,-788,314
-608,-660,-696
395,571,-809
681,835,531
471,496,-742
-779,484,347
-835,348,-640
--- scanner 9 ---
-539,-718,-844
485,-535,-554
950,532,-710
-601,-526,777
-468,-507,725
-306,518,-866
-518,-635,-889
843,561,471
529,-527,269
-428,897,771
-443,837,726
854,592,-796
165,-21,-100
-564,-560,-804
512,-594,283
-500,-442,666
623,-511,310
-406,481,-984
551,-476,-698
835,523,629
-425,707,769
485,-398,-556
801,540,-734
794,573,531
-395,561,-866
--- scanner 10 ---
-539,528,-785
620,-478,-368
-509,-552,-501
472,735,835
442,537,768
-409,441,480
-353,397,577
-620,488,-641
-541,-449,834
7,-85,106
558,599,-320
475,-708,553
470,-533,500
-457,-371,793
-438,-579,843
671,-575,-376
575,-582,-440
-566,545,-629
612,510,-246
-499,-609,-305
-508,-436,-324
410,747,800
692,691,-273
-285,339,419
493,-691,512
--- scanner 11 ---
367,-454,-454
475,806,-642
-114,30,-142
-781,625,591
663,-462,285
-662,741,-663
293,-635,-454
-640,-602,-611
-467,-463,793
329,-606,-428
487,771,293
490,961,291
-704,757,-762
-647,-726,-486
-773,587,433
530,-443,337
494,886,-611
-450,-530,779
452,793,-450
-732,637,531
-37,123,4
-661,-479,-471
562,-378,396
-561,-447,752
-663,829,-700
505,901,336
--- scanner 12 ---
-844,-686,-461
831,-405,-512
426,754,489
357,704,-659
-535,558,362
240,669,-581
387,779,-588
-32,121,-94
546,-425,440
-739,625,-706
-950,-740,552
-134,13,56
-803,-521,-396
-897,615,-832
-867,-575,-539
525,712,505
-817,-761,693
738,-402,453
488,713,417
577,-444,360
-527,519,429
760,-356,-623
-880,-719,693
-773,717,-859
828,-416,-540
-600,613,325
--- scanner 13 ---
406,-575,574
478,781,-595
-134,-129,85
-670,464,522
407,496,771
-798,-546,911
639,-645,-613
-729,-542,956
-503,599,-446
249,459,834
-671,-503,945
-488,508,-335
-48,18,1
-757,451,594
-729,-591,-360
256,504,653
-398,594,-305
-681,248,591
-580,-672,-374
-475,-585,-371
602,-480,-661
439,-452,509
414,-486,712
638,-472,-505
600,664,-596
587,784,-475
--- scanner 14 ---
-694,776,767
-533,741,-630
-404,-717,-823
483,-706,316
-80,1,-140
-532,-351,541
468,-694,555
773,798,463
-608,817,-563
-690,-389,458
710,704,365
-386,-711,-803
57,172,-101
740,549,-462
711,631,-518
-765,794,566
616,866,403
562,-696,514
363,-454,-536
692,469,-502
-451,-758,-714
415,-230,-543
-569,-418,512
325,-332,-586
-833,775,707
-552,786,-462
--- scanner 15 ---
-12,-84,63
-772,-427,-692
-793,-461,-733
719,552,669
414,460,-823
-630,-742,273
508,501,-825
-744,557,-518
483,-454,-546
-571,-818,397
471,-420,762
-819,449,665
-887,308,646
370,-541,-534
-136,-25,-123
-586,474,-480
-668,-430,-870
-748,248,647
294,-461,-644
562,612,737
-623,503,-547
429,699,-835
656,650,575
-690,-758,408
585,-433,754
439,-441,625
--- scanner 16 ---
596,-593,418
-820,646,-381
638,802,-496
-1,71,103
-674,518,-399
-916,-524,664
647,-609,-454
-620,529,537
-792,-560,601
587,786,666
-107,-67,179
-479,548,469
817,-647,-500
609,832,-520
-799,593,-449
-626,-312,-582
710,845,-383
676,-722,-453
-609,-487,-657
600,-678,475
-850,-619,611
-419,547,608
-646,-423,-598
571,921,726
565,-613,403
647,797,785
--- scanner 17 ---
-404,492,-456
896,680,623
63,-49,38
-340,577,-451
-620,526,812
775,-306,871
-40,89,-73
743,-354,-543
-616,611,869
658,-368,802
544,762,-486
772,644,686
-651,-359,-631
861,-369,-706
555,804,-330
-465,-590,412
-604,-339,-596
-383,-598,308
-488,-595,452
-440,559,-580
589,730,-401
-584,-538,-599
-585,591,884
635,-291,900
867,-378,-607
830,585,676
--- scanner 18 ---
664,-543,735
638,469,-766
678,457,392
-700,-415,369
637,551,390
635,-580,668
-39,-39,37
-698,-711,-544
-818,-698,-665
-815,-589,-545
-420,404,856
119,8,-73
-463,314,754
446,-713,-479
581,-701,697
439,472,380
-413,352,632
-591,-462,328
-628,287,-835
-680,-397,375
557,618,-780
-542,377,-805
-633,392,-694
438,-749,-635
611,-750,-527
551,364,-769
--- scanner 19 ---
473,682,455
-834,-721,461
587,626,546
564,-479,651
-545,-765,-540
-78,-2,-37
-711,617,612
-722,496,598
831,531,-771
-518,616,-871
614,-696,-440
726,-573,613
855,473,-742
719,416,-765
647,750,477
-490,459,-778
-451,525,-896
-846,-706,700
-737,628,496
751,-664,-419
-557,-652,-453
743,-550,-432
658,-416,553
-655,-841,-460
-836,-627,502
--- scanner 20 ---
809,-632,570
-591,-730,-747
629,-731,-555
582,721,920
-714,-709,-607
705,-538,497
-487,-653,401
681,383,-768
-538,-771,400
-554,270,418
694,406,-576
772,-577,505
-747,224,-764
-566,298,-764
-543,334,537
441,700,850
-838,-716,-732
-527,267,556
-718,260,-790
774,425,-607
441,742,787
-668,-705,391
40,-182,76
717,-732,-518
645,-773,-456
-127,-81,-24
--- scanner 21 ---
533,-731,630
788,548,552
684,716,-498
-271,702,-440
554,791,-559
571,-655,690
167,144,161
-344,778,-442
-751,-420,-734
-631,565,434
683,683,603
469,-591,-728
140,-18,49
-649,-736,760
-742,-538,-701
407,-753,658
-800,529,376
554,-525,-666
-785,-445,-715
508,-638,-686
-647,-639,771
698,631,500
-765,457,403
603,719,-634
-308,674,-285
-538,-693,781
--- scanner 22 ---
62,5,12
-313,488,594
-312,-645,454
-381,692,-711
479,-656,617
-312,-464,380
-344,-373,-560
538,-721,649
-298,520,434
-352,774,-767
-286,-493,416
880,699,-452
-469,-497,-553
-329,-620,-574
921,-569,-363
460,640,541
165,120,110
791,697,-450
-400,854,-727
718,808,-445
-341,413,457
427,-637,750
522,471,500
935,-636,-380
894,-652,-474
430,539,380
--- scanner 23 ---
584,-628,701
687,619,544
509,-313,-531
429,-353,-579
591,-369,-560
-572,-433,523
573,710,600
758,612,-498
-746,465,-788
-494,-387,-908
-734,704,-803
747,688,668
-372,-437,-946
-736,663,-709
-270,-394,-856
-622,567,414
-632,-441,668
-611,553,535
-661,-423,532
664,514,-561
586,-630,612
475,-635,539
-637,669,546
826,552,-655
39,30,-173
--- scanner 24 ---
-403,-570,-427
835,-850,759
-354,587,-617
618,567,574
-509,-951,874
647,-674,-595
638,706,-432
563,799,-377
-541,-787,776
57,-145,118
-374,729,-603
-335,546,825
708,-804,-670
673,679,471
663,719,575
751,817,-465
-351,-660,-510
877,-889,712
101,27,2
-360,680,947
783,-755,-598
815,-804,646
-335,735,-735
-454,-675,-562
-481,-825,852
-281,654,798
--- scanner 25 ---
483,-365,519
562,-828,-670
93,27,-47
-415,786,411
664,518,-347
883,371,601
-574,548,-810
904,504,742
-505,-426,-416
-472,424,-783
-376,794,478
-470,721,374
-12,108,76
-482,582,-657
487,-526,567
721,-840,-748
829,477,-412
718,454,-490
-440,-812,687
-446,-560,-430
-371,-487,-404
639,-791,-711
-483,-706,741
604,-431,547
-525,-794,680
862,441,742

102
inputs/day20.txt Normal file
View File

@ -0,0 +1,102 @@
##....#..#####...#######...##.#..####.###.##..###.####.#....##.##.##.#.#####.#.#.#..##.#...#.##.##.#...###.####..###..##.#.#.#....#.#.#..##.....#.##.#.....#..###...##...#####.##.#..#.....#.#.#.#.#.####.###...###..####..#....###..######....####.#..##.##.###.#..#.#.#.###..#.##...#.###.##.#.###.#...#...#....###.##...#.#####.#..#.##..#.##..###.#...###...#######.#.......#...##........######.#########..##.##...##.#...####.....#####....#######..#..###.#####..#.#......#.##..###.####..##...###.########..#.##..#..#..
.....#.#.##..##.##.#.###...#.#..#..###.#...#.#...####.###.....#..#.##...##.##.#.#.#.###.##.#...##.##
##..##...##..#..####.#.###....#.###..#..#.##......####..#.###...#####.#...#.##.###.###.##.##.##...##
.#..#.#.......#.#.#..#.#.#...###.###.###.###..#.##..##.###.##..#.#....##.#...#####..#..##..#####.##.
####.#######.##.#.....####..##...#.......#.###.##.###.###.#####..#.#######.#.#...#.#.#..####..#.#...
##.#.....##.#..#.#####.###.#.#..#.#..#.#.....###.#.##.#..#.###...#####..#..#.##...#.##......###.##..
#..####.######...#.#####.########.#.#..#.#..##.##..#.######.#..#...####.#.###.###..##..#.#.....###.#
...###..#.####.#..##..###....##....###.##.#...#..#..#..#...##.##.####...###.####.###..#.##.##..#..##
.#.#..#...#..###.####...##..#.#...#...##..####.#..#..#....#...##..#..#.##..##.#......#.###.###.#..#.
......##..#...#.....#.###....##...#.##...#....#..##..#..##..##..#...###############.#.####.###.##.#.
#####.##..#.#.#..#.#..###....#....#......#....##.#.##...##.##.#.#....#.##.##..##...####..##.....##..
#.#..#.##....#......##.###...#.##.#.##.#.#..######..#..##..####.#.#####..#.#..###....##..##.#.###.#.
.###.#####....#.#.###.####.......#.#.##.....###.##....#.#.#....#.##...###..#..#.##.#..##.#....#.#.##
..##...#####..####.####..##.###.#..#..######......##..###....##...#..#..#...#.##..##.####..#####..#.
.#..#.###..#.##..#.#.#.####.#..#.#..#..####.####..#.#..##..#.#....#.##.###..#.#####.#..#...###..#...
#.######..##.#.#.#..#..##....#.......#####.###.##.#.##..##.###..#.#...##.#.#...###.#..#..#....#.##.#
#..##.##..#....#.#.###...#.##.#.#.#.....###.##.###..##.#.....#..##.#...###.##.###########.#.#.#.#...
.##.########.###...####.....###....#.##...#..##..##.###......##.##.#.#.#...#...####...#.##...#..#.#.
##..#.#.#.####...##......#...##.....#.#.###....#.##.....#.#.##.#.########.#......#...##.##.#.#####.#
...#.#....##.###.#..####...##..##...#...###.###.#.###...##..#....##.##..#...#.#.#..##.###.##..#.##..
###.#.###..###.##..#....##.#..##.###.#....#......#######..#.#..#...###.#..##.###.##.#####.##..#.#.##
.#..##.#####..##.#..###.##.###.#.###.#....#.###.##.#.....#...#..#...###....#.#.####....##...........
.#.#..##.#.###.#....#.####.##..##.....#..###.#..#.#.#...#..#....####..#..#.#..###.##.#..####.####..#
##...###..##.######.#....#..#.#.###.###...##.##.#..####..#..####..##...##....####..#...##.#.#.###...
###.#...#..#.#..#..##.##.##..##.#####...#..##.#...##.#..#...##.####.#.##.##.#.##.#......###.#..#....
.....##.#...#.#.#.#...#.#.##.......#.#.######.#..#..##.##......#...#.###.#....###..#..#.##.##.##....
####..##.##...#.###..#...#.##.####.#..#.#..#.###..####.##.#..#..#.##...#####.#.###.##.###..#.##...#.
.##..#.#####.#.#....##.###..##..###.#.#.#.########.##..####.#.##...#.##.##.##.#.#....#.####.#....#.#
#####..#.#.#.####...#.......#.#..##....#.#.###.#..#.##.##.#.#..#....#..#######.#....#......#.####..#
.....###...##...####..#...###.##.#.#...#...#.#..#...#.##..#..#..###...####.#...#....#.##....###...#.
##.....##..#...##.#.#.###...#.###.###.#.#..#..##..##.#....#..#..#...####.#...#..#...##..###...##...#
#.#.##.##..##......##..####...#.##.####....##....####..##.#...###.#.##.#..###..#..###..###..#...#...
#.##..###.##.#..#####.#.##.##..###.#.##.....#.....#...#.....##.#..##..#....#.#..##...##.#.####.##...
..#.#.#.....##.#...#..#....##..##.##.##.#.#.##.#...####..#..#...###.#..##..##...#####.#...#.#...#.#.
.###.##.#.######..#.#..#...#.#...####.#..###.###..###.####.###..#...#.#...######..##......#..###...#
.#...#.#..#.###....#.##.####.########..###.#.#.#.#.###.#.#.##.##...######.#..#...#...#..#....##.####
###.#.#####..###..###.###...###.....#####.#...#.###.#...#..#..####...#.#..###..#.#.......#.....#..#.
.##.#.#..##..#..##..##.#.###.##.##..#.#.##.##.##.#####...###.##...#..##.##.#..##.#.#.###....##....#.
....##......#..##.###.##...#.######.#.#...#.###.######.#.####.....#.####.###....#..##..#.#.##.#...#.
..##.#.......#....#.#........#..#..#..#...#.#.####..#####....#.....##...##.....###.#.#..#.##..##...#
.#.###.###....#...#..###.#######..####.....#.##..#.#.#..##....#.##.#....#..#####.#..#.#######.#.#...
...#.....###.#...#.#####..#..#..#.##.##.#......###.#..#.##.##.####..##..###.....##..##.#.###...#.#.#
##...#.###.#.#.#.########.#.#.##..#.#..##....###.#..#.#........#.#......#.#.#...###...#.###.#.....##
##.#...#.##.#.###..#.#.#####.####..##....##.##....#.##.##.#.##..#..#...#...##.#####.##...#####..#...
..#..#..#####.#..#.#####..#..#......#.#......###..##..#..#.#..##.#####....####...#.##..#.##.#######.
.##.....#..#.##...#...#.###.#.####...##.#...###.#..###.....#..###..####...###...#...#...#...###.#.##
#.#####.##..#.##.###.....#.#####..#.#######...###.#####...#.###..#...#.....####..##..#.#..#..#.#.#.#
.##.###.##.#....#..###..###.##..####..#.....####.##.#..#.##.###...#.....#.####.##....#.#....#.##.#.#
#.#..########...#.#.##....##.#.#..##.#..#.#.#.##...#..##....######.#..##.#...#.#....##.#.##..##..#..
.##..#.##.##...####....#.##..####..##.##..#...#...#...######.#..##.#.....#.#......####...####...####
#..###..#.######...#...#..##.#....#..#..#####....#.####.#.#..###...#.####..#..####..##.##...#..#.#.#
#####.#.#.##..#....#.##.##.###...#.#.#.##..######.#.#...#.#.##.....##.###..#..##..#...#.#....###.#..
#..##.##.###.##..##.#.#.##.##..###.#..##.###...##.####.##..#.....##...##.#.######.###.##..###....##.
#.##....###..#..##.###.#...#.####.......#....##..#.#####..#.#.###########.##.##..#..##.#......######
###.##.###.##.#####..####.#####....#..##.###.....#..#.#.#..#.#.##..#.###..#..###..##.#####...#.#.#.#
#.####.....#.#.##..######......##.#..#.##.##.###..####..##..##.##.#.##.#.#.#..##..#.###.####..##..##
.....#...###...#...###.#.###.#.###.##.#.#...##.#.#..#..##..###.#..#.##..##..#.##..#.#.#.#.#...#.#.##
##..#####....#.##.#..##.##.....##....###..###...####....#..##..#..#.##.#.#.#.#.....#.##.....##..###.
######.#.##.###.#.#..##.#.##.##.....#.##..##.#..#...##.####..##.##..##...###.#......#####.....###.#.
.#..#.###.#..###.#.#.##..##..###....#.#..###.##.#.##..###...###...##.##.###...#..##.###....######...
##..#...#....#.#####..##.####...#...###........###..#...#.#.#.##....#..#.#...###.....###......####.#
.#..##..##...##..#...###..##.####.##.#..#.#.#....##.##...#....###...###.##.#####.##.#...##.####....#
......#....#####...####.##..#.##....###..#.#..#.....####.#...##..##..#.####...##..#..##.#.#.....####
##..##.##.#####.#.####..###.##.###..#...##..#.#.#....#######....#...#...###.######....#####.##.#...#
#.#.####..#.##..##.###.#.#...#.#......##.###...####...#.##...#.#.#...#.#.##..##...#...##...###.#####
##....#.#######...##...#....#.##.#..#...##..#.#.#####.###.###.#.#..##.###..##.###.#.#.##.....#..##.#
#.#.#.#...#..##.#..#####.#.###...###.#####....####...#.#.#...#...##.#...##.######...###...###.##..#.
.######...#....#..#......#.#####.#....####.#....#.##..#.#.#.#..#.##.##...##.#.##.#####.#.###.#..#.#.
#.##..#.#...####....##....#.######.###.##.######...##.....####.#.#..######.###...#.##.#####.###.....
..##.#.#..#.##.#.#.##.##..###..#..#.#.#...##.#..#......#.#######.###.##.#...####.##..###..#.##....#.
.#..#..####...##.###....###....#.#......#..#.###..#..#.###.#.....#.###.#..###..###..#.##.###...#...#
.##....#.#.###......#..#.#..###...######.#..#.####..###...#.##.#.##....###..#..###...##.#.#...#.##.#
.##...#..##.###.###.#....##......#.###.####...##..##.##..##...###.#.#.##.#..#...#.#..###...####.....
#...####.##......###.#####.#..##...#######.##.#####.###.####...##.##.#####...###.###.####..##.#...#.
###...#.#.#.#.###....##..###..####.##..#...#.#.##.##.##....##.##....#.....#...#......##....#...####.
##.####.....#.##.####..#.#....#######.######..##.##.#..###..#.....#..###..#.##..#...#...###.##.##..#
.#..#.#.#.#.####.#..#...#..#.##.#...#..#....#..##....#.##...#.##...#.#..##.#.##....#.#..#######..#..
.#...#.#.#........#.##...####..###..#####..#.#..#.....##...#.####....###.#...###..#####..#...###.##.
##.#.#..#.####..###.#.##.#...##.#..##.###...#.##.##.#####....##...#.#..####.#..#..##.#.#.#..#..##.#.
.#....#..#..#.##.######...#....##..##..#.#...#.##.##.#######..##.##..##..##.#..#.##..####...#.#....#
.#...#.......######...##..#..####....#.#...#..#.##.#.#.#..##.######...#...#.##.###.##..#.####.##..#.
..#.#....##..#..####.##..#..##..#.#.#.#.#...#...##..#..#######..##..##.#..##..#..####.#.#.#.#####..#
##...##.##..##....##..#........######.#.#.#..#.#.#.###...##.#.##..###....#.##...#.#...###.#.###..#..
##......###.#.#......##.#.##.####.#..#...###..##.######.######.#..#####.#...##..#.#..###.####.#.##.#
..##.#..#.#..#..###..##..##.##.#####..#.##....#..#.#.#..##...#.##.##.....##.##....###...#.#.###...#.
###...##.##....#..###...#.##.##.#.#.##.##.###......#...#...#.###.#....##.#.###....#.#.##.#...##.#..#
...#.#.#.#.##..#.#.##.....##.#.#..#...#...##.##..#..##.#####...######..#.##..#.#....###.#.#.##.#..#.
....#####...#.#.##.#...####.......#.#...#.......#.##.....##.##..##...##....###.#.###.....###..######
.###.#...##.#...#.##.##..#.#.######.#..##......##....#....#.....#.#.##.##.#####.#...##....#.........
..#...#..##.#.###.##....#...######....#.#....#.####...#...####.#..#.....####.#.....#..#..#.......#.#
#####..#.##..##.#####.#..##...##..####..###....#....##..#.##...#.#.#.#.#####.#.#...#..##....#.#.###.
..##.#.##.....#.##..###...#.##.#..##...##..#####..#..#..##.#####.####...#....#..##...#.#....####..#.
.##.##....#...#...####.##.#.....###.#...#.#..#..####.#.##.#.##.....#.#.#..#..######.#..#.##.##....#.
.....#.##.#......###.#.#..######..#..#..#####..###.......#.#.##..#.#....####..#..###..#....#.##....#
##.##..##....###.#####...####..##...........##.###..#...#..##...###.#.####....####..#.##.#.#.#.####.
.##.....##..#.#..#.#.....#.#.##....##.#..#.##.#..#.####.##........##..#.##...#.##.#.#.........####..
#..##..#.###.##..#.###..#######.#..#..#...###....#.##..#..###.###.#...#.##.....#......#...#..####...
.#..##....##.#..#..#.#...##.##.#.#.#..##..##...#....###..#.##..#.#.####.#.#.#.#..#.#...#.#..#..#..#.
#####..#.......#.###.#.######.##.###.#.###..###..##.#..#....#...#..##.##.#####..#.#.#.##......#.###.
....##...#.#.##.####.#....##.##.#####.#####.#.#...#.#..######..####.###...#.#...#.#....###.#....##.#
.###...##.#....#..##.######..........#.##..#.#....#.....#.#####..#.#..##......#..#...#.###.#.#.#...#

2
inputs/day21.txt Normal file
View File

@ -0,0 +1,2 @@
Player 1 starting position: 8
Player 2 starting position: 7

420
inputs/day22.txt Normal file
View File

@ -0,0 +1,420 @@
on x=-4..48,y=-30..24,z=-39..15
on x=-19..33,y=-15..29,z=-4..42
on x=-1..49,y=-14..38,z=-27..20
on x=-28..16,y=-16..36,z=-21..27
on x=-23..27,y=-26..20,z=-23..22
on x=-8..43,y=-10..43,z=-21..30
on x=-45..4,y=-6..47,z=-15..33
on x=-22..22,y=-6..45,z=-29..19
on x=-30..18,y=-47..-3,z=-24..22
on x=-6..43,y=-37..8,z=-19..27
off x=18..28,y=-15..4,z=32..49
on x=-2..45,y=-17..35,z=-15..34
off x=-49..-33,y=-49..-31,z=-10..5
on x=-31..21,y=-12..34,z=-48..6
off x=-38..-27,y=-44..-25,z=-17..-4
on x=-21..32,y=-9..45,z=-18..33
off x=-14..3,y=-10..-1,z=-40..-29
on x=-30..16,y=-13..34,z=-4..45
off x=24..34,y=13..32,z=-38..-25
on x=-27..26,y=-14..38,z=-24..22
on x=35544..55136,y=51736..62748,z=-58537..-33425
on x=33690..50869,y=-78828..-40948,z=-44269..-23196
on x=65407..77846,y=-1962..21102,z=30745..35336
on x=43820..63036,y=45669..68304,z=-27802..-19946
on x=-80968..-79217,y=-15189..550,z=-20396..-2177
on x=22543..55131,y=-50184..-36252,z=46098..64106
on x=-12595..7924,y=-24867..-13344,z=-96867..-68102
on x=9874..31255,y=65277..89043,z=-936..16277
on x=-13411..5153,y=-10968..4147,z=-87107..-78849
on x=-8897..8799,y=57380..81655,z=9642..37776
on x=67474..84855,y=-6483..10922,z=41290..57415
on x=-8012..1755,y=34193..64326,z=48900..73023
on x=54961..78882,y=-7659..5406,z=36768..70357
on x=4538..32860,y=-47844..-36498,z=51393..73621
on x=16397..28684,y=16381..47358,z=-87090..-57131
on x=38468..57198,y=-14413..-5639,z=-67748..-57437
on x=-60663..-47089,y=-34032..-26482,z=49838..59849
on x=-35900..-24050,y=-62434..-43634,z=35478..45195
on x=39580..65361,y=49921..69519,z=19635..40186
on x=72891..74867,y=-42056..-22591,z=-6916..20783
on x=1951..24816,y=-74448..-64168,z=-36633..-31963
on x=24833..49754,y=20298..43211,z=51546..73514
on x=-3167..30380,y=35722..38122,z=-76109..-57000
on x=-82903..-79067,y=-8395..20541,z=-5265..4392
on x=3218..14953,y=-13800..-1624,z=-89481..-62873
on x=-53283..-38277,y=1641..4903,z=-70901..-45748
on x=-32141..-25640,y=-34847..-13896,z=69407..86876
on x=37990..61788,y=44601..58722,z=-49195..-29888
on x=46963..82000,y=-20841..-6866,z=27132..57574
on x=53439..75061,y=42180..56045,z=-29192..-7810
on x=56225..83464,y=-29936..-24016,z=9181..40276
on x=-25381..6615,y=-36495..-470,z=-92049..-72629
on x=32658..54160,y=47754..70225,z=-6772..7057
on x=1541..22570,y=64100..80080,z=-46051..-26336
on x=290..25368,y=-75499..-38271,z=-71991..-44993
on x=-90436..-74173,y=-16161..9329,z=-6785..12872
on x=-77341..-60209,y=12324..44621,z=-14282..15269
on x=43442..74799,y=38197..48084,z=9898..46142
on x=-8617..-3246,y=-18762..3821,z=-87843..-72818
on x=30362..51314,y=-8722..8473,z=54067..78087
on x=-27208..-9871,y=10214..23370,z=70814..83559
on x=-34980..-14547,y=-78208..-70283,z=-27640..-3899
on x=-42751..-6005,y=44998..73226,z=34016..57989
on x=-82302..-64007,y=13489..29455,z=-38227..-20899
on x=-11988..12700,y=-28404..-6516,z=-90902..-70602
on x=33172..47497,y=-22050..5845,z=63959..73452
on x=4520..20681,y=53723..81778,z=42603..64776
on x=9456..39703,y=48507..61312,z=-51529..-40905
on x=-40098..-6364,y=30241..51715,z=-80424..-53739
on x=12558..41048,y=-75142..-67808,z=-28847..-5450
on x=-45305..-37476,y=59373..65800,z=30613..52009
on x=-51862..-28691,y=-80526..-49298,z=7585..33680
on x=33988..56509,y=-76294..-52403,z=-24060..8376
on x=66701..87231,y=-14532..2225,z=-2979..12349
on x=6390..28035,y=24319..41006,z=66533..72374
on x=-92154..-59055,y=17719..22642,z=6955..28468
on x=33232..43716,y=-9213..10287,z=-76824..-69144
on x=-15670..8102,y=55811..91367,z=-36831..-16337
on x=-11992..-4723,y=51539..87697,z=23232..47761
on x=-5295..18741,y=-72590..-48553,z=-73622..-40811
on x=18186..41716,y=67026..78411,z=-34911..-5988
on x=-68762..-64823,y=-45789..-18913,z=9605..45048
on x=-12471..-8333,y=-49562..-33936,z=-68222..-58934
on x=-1314..15331,y=-30976..-16222,z=67572..84940
on x=-67163..-61062,y=-53863..-18643,z=-47613..-15657
on x=71390..87446,y=-28061..-15108,z=-17260..5398
on x=43837..73348,y=47081..51019,z=-27859..-13016
on x=38886..48555,y=44108..70423,z=28181..43111
on x=-77134..-58601,y=-13936..11454,z=22269..39015
on x=16000..20829,y=-96924..-65406,z=-17350..6468
on x=-63622..-40677,y=39467..48832,z=28335..33734
on x=-83957..-71425,y=18893..29929,z=-11533..-2293
on x=-92470..-69285,y=14707..19654,z=18369..26120
on x=13641..38318,y=-32184..-19122,z=-82832..-59293
on x=38368..44793,y=7451..23119,z=-79164..-55642
on x=-34078..-24088,y=37612..70266,z=-57847..-30148
on x=45511..61076,y=25218..47528,z=21820..50200
on x=-9251..14390,y=-26731..9955,z=-84053..-62781
on x=7166..29475,y=65191..78750,z=-56267..-31353
on x=-1215..16834,y=-98600..-71219,z=-235..21112
on x=66193..69134,y=28687..42487,z=-17341..-7323
on x=-32865..-5842,y=14478..43666,z=-87864..-55075
on x=40182..48489,y=57444..85093,z=-21528..-5631
on x=-37152..-5019,y=30492..43671,z=56217..78887
on x=46382..55909,y=-67994..-58067,z=-16846..-3160
on x=32700..56924,y=22430..44279,z=41830..63068
on x=26774..34296,y=-80268..-60786,z=13217..29206
on x=-5802..1019,y=34264..65124,z=50883..74910
on x=-42392..-13729,y=13094..41810,z=-79316..-51263
on x=-16021..473,y=57439..86998,z=-46753..-30286
on x=-62595..-45603,y=4608..9583,z=57915..82579
on x=-4473..1973,y=57840..73813,z=-68167..-33772
on x=-83547..-62073,y=-33126..-18871,z=-17468..2918
on x=-46545..-39844,y=-70331..-60310,z=13062..37682
on x=-31519..469,y=-711..7423,z=-94431..-62298
on x=60002..89047,y=-29111..-9661,z=12744..28690
on x=-1450..20279,y=-13723..5802,z=-98979..-77404
on x=-7347..23250,y=-90904..-68475,z=-38218..-31606
on x=-15622..-8177,y=62746..92916,z=-31184..3126
on x=-53804..-52634,y=45539..66268,z=-46218..-7476
on x=-65959..-57397,y=36117..52643,z=19481..45747
on x=43928..54629,y=8065..16553,z=-72837..-47865
on x=-77510..-62388,y=-54448..-20445,z=-16968..15103
on x=28751..32027,y=-47236..-17317,z=55145..71895
on x=-63166..-38470,y=-77573..-47295,z=-20443..6131
on x=28272..58068,y=53583..65317,z=5882..27642
on x=-87017..-47718,y=-29823..-6062,z=24910..39735
on x=9462..38606,y=66092..87363,z=14791..34975
on x=60870..83615,y=16444..35987,z=-1375..18757
on x=-61017..-51891,y=38733..57918,z=-55845..-32294
on x=17842..45753,y=58058..78326,z=16889..44761
on x=66304..81980,y=-51921..-35554,z=-1171..8798
on x=-33872..-17168,y=37853..39657,z=48783..81069
on x=17025..42143,y=-32845..-10455,z=65973..83280
on x=35256..55278,y=-72080..-40057,z=7549..32601
on x=30028..53691,y=-15660..2864,z=55672..84796
on x=-93477..-72259,y=13273..37746,z=-13865..-732
on x=8114..19004,y=61128..80348,z=40437..54937
on x=35042..46361,y=23302..44970,z=57849..81964
on x=15670..27956,y=-50201..-32885,z=43089..78261
on x=-22149..-4701,y=70832..92978,z=-18375..8955
on x=-11307..5395,y=64032..80176,z=16681..41609
on x=-43425..-28061,y=67202..74457,z=-36752..-9283
on x=-47157..-23853,y=22746..46164,z=59388..69758
on x=-66470..-41360,y=24611..42210,z=-58386..-38174
on x=24871..39254,y=52512..83471,z=-2514..17277
on x=9854..12006,y=-42027..-22328,z=-78647..-71822
on x=-63822..-45142,y=-74770..-40518,z=-12693..-1226
on x=7514..29519,y=-70540..-40815,z=50673..66670
on x=-86355..-64456,y=1739..18125,z=21907..45251
on x=23938..36472,y=-35351..-19431,z=56359..87714
on x=-61952..-33569,y=51907..81871,z=-38456..-18781
on x=54670..64202,y=19047..45756,z=-35785..-24071
on x=-62952..-32348,y=-23703..-756,z=64776..79497
on x=42131..72686,y=43348..69631,z=-12082..9850
on x=19070..30412,y=980..20591,z=-90809..-62142
on x=-9351..-4058,y=46899..70855,z=-57535..-32949
on x=58882..72704,y=21502..45491,z=26413..44449
on x=27826..59456,y=-80504..-41682,z=17382..44358
on x=-48248..-41584,y=23606..41769,z=54404..66807
on x=803..3373,y=-78943..-70599,z=14956..29213
on x=-77364..-60633,y=-36875..-17085,z=-1174..21376
on x=-71159..-63592,y=-30044..-11779,z=-61398..-36500
on x=-69639..-51727,y=-25463..-11440,z=35873..47448
on x=-14747..1355,y=-90524..-63391,z=-33627..-15447
on x=-14250..14802,y=-51215..-28495,z=61720..73235
on x=-34423..-6304,y=-44713..-24670,z=65483..74818
on x=62322..90758,y=13367..39938,z=7438..27708
on x=46367..81400,y=11677..35279,z=-47304..-24771
on x=4379..23035,y=61932..84911,z=-63724..-43631
on x=-89042..-68392,y=-5068..16120,z=-14807..4087
on x=63034..91408,y=-10916..23888,z=12401..43459
on x=-82262..-59907,y=3979..40319,z=-1175..25220
on x=16006..42587,y=-72561..-58071,z=-33042..-9704
on x=68016..92195,y=8804..14233,z=-33255..-1477
on x=-50921..-37413,y=45745..81563,z=1283..20895
on x=11428..31965,y=47684..73555,z=26199..46769
on x=-22972..1981,y=16390..37660,z=62583..75045
on x=33829..56047,y=53258..57241,z=-44084..-20261
on x=-84051..-68366,y=29094..43279,z=-17225..10812
on x=50085..75114,y=6497..31618,z=-37737..-17385
on x=17484..32905,y=-48591..-23834,z=-75180..-54610
on x=51877..82949,y=-18174..-5750,z=-53652..-42825
on x=32775..58264,y=-11346..9920,z=57936..66561
on x=-52169..-28507,y=-90305..-53670,z=-19641..13206
on x=-71218..-41412,y=-59994..-48983,z=15647..33905
on x=26805..52467,y=62380..84830,z=-4520..10963
on x=-4087..2092,y=71217..97333,z=8093..33139
on x=-80230..-57401,y=-31567..3147,z=39782..58307
on x=-80572..-67522,y=31920..50297,z=-7054..10350
on x=-71271..-49989,y=-37730..-28383,z=37368..55962
on x=-75528..-56735,y=37170..52802,z=-34426..-19488
on x=64763..85408,y=-7784..5034,z=-41782..-15632
on x=-61687..-55301,y=54758..61276,z=-15846..9067
on x=30543..63245,y=-18542..-4101,z=-79361..-45457
on x=-14932..5661,y=54028..79525,z=-61556..-32216
on x=24493..31197,y=-34578..1825,z=63560..86978
on x=-61036..-47222,y=14404..38815,z=29338..54873
on x=-38192..-8201,y=-81948..-57915,z=-17188..10726
on x=1990..15491,y=56137..78488,z=-42010..-28371
on x=5049..33267,y=-79591..-57008,z=-42567..-22184
on x=24693..34274,y=24506..45113,z=-79046..-65370
on x=68172..98565,y=-14312..8628,z=-9721..13285
on x=-18235..6826,y=-25122..10050,z=60096..85636
on x=45928..69951,y=-60287..-37529,z=-20540..7359
on x=-32041..-5059,y=51092..63261,z=-66204..-31843
on x=63653..71469,y=-34873..-31161,z=14048..39702
on x=22396..43880,y=-3824..14660,z=-90531..-56170
on x=-1717..21789,y=53858..67026,z=-58144..-47816
on x=-51019..-40959,y=-75814..-60550,z=11755..46123
on x=-57489..-39503,y=-64465..-33404,z=-48668..-30131
on x=27760..59108,y=42790..67256,z=17743..35790
on x=-43692..-29811,y=-88277..-59083,z=5968..37461
on x=-47420..-22185,y=-68408..-52385,z=23869..44928
on x=39709..61505,y=-21268..1882,z=-76594..-60038
on x=54698..76952,y=-17074..10219,z=24567..44175
on x=-95465..-62390,y=-29895..-23300,z=-11863..4898
on x=23365..40278,y=58938..80416,z=-21545..9812
on x=11923..35757,y=-66990..-41080,z=-61382..-33846
on x=67045..75089,y=-11897..4681,z=-47955..-24267
on x=-90376..-59893,y=117..26316,z=28188..35096
off x=24651..28210,y=-24590..-10312,z=66417..75292
off x=-43951..-18830,y=-69398..-52261,z=28497..50225
off x=42514..62323,y=-60372..-24865,z=37347..49320
on x=49798..77900,y=-72682..-49927,z=-10258..958
off x=24604..45145,y=36058..57891,z=-53557..-34761
on x=-65518..-39972,y=34159..54763,z=-17646..9176
off x=-76836..-49612,y=27033..40308,z=24773..37790
off x=41029..63639,y=34627..54572,z=-60195..-35060
off x=5440..40626,y=31825..56887,z=58565..74579
on x=-85410..-68908,y=-16763..12913,z=1884..24605
on x=-70712..-56718,y=-48053..-38417,z=-37942..-32604
off x=-66574..-45489,y=34467..41894,z=-46802..-24009
off x=-30928..-7167,y=43518..70824,z=33329..64950
off x=-52088..-17091,y=-28441..-10616,z=56304..83190
off x=73277..76646,y=-5922..10725,z=23075..35243
off x=-44861..-12403,y=-18397..9805,z=-90975..-64778
on x=-19159..-8086,y=-84649..-57626,z=-4777..30377
on x=-48235..-45399,y=-76542..-41786,z=-27853..-11708
off x=-41696..-17405,y=-81352..-58226,z=-51727..-15321
on x=-21612..8433,y=-88881..-57104,z=20197..38496
off x=64866..82781,y=-35287..-19222,z=2225..31593
off x=-60086..-31957,y=-66807..-52584,z=-47785..-31167
on x=-75232..-65410,y=6879..15928,z=25821..33108
on x=49721..74332,y=-32211..-5492,z=37490..67240
on x=-69008..-59258,y=-67365..-39177,z=2702..22494
on x=40598..77320,y=-44858..-24495,z=-39106..-18658
on x=-66046..-43012,y=9311..31541,z=51758..55618
on x=-74902..-54476,y=9991..38601,z=-18468..-2400
off x=934..27205,y=-52862..-47494,z=-78005..-46221
off x=36318..42994,y=63750..79912,z=-11834..6870
off x=-9448..6260,y=69407..96104,z=3742..26473
on x=34180..59194,y=56640..70053,z=-6782..2219
off x=-71868..-58289,y=-50419..-43052,z=-16738..3185
off x=-55443..-21609,y=-43083..-21999,z=-75650..-51578
off x=-3124..2680,y=26555..50324,z=-84693..-65786
off x=65726..80418,y=-21970..-4777,z=28280..55831
off x=-12755..2382,y=21228..27803,z=-80546..-62078
on x=-70824..-46210,y=-46992..-35115,z=-6484..18899
off x=19667..33161,y=59955..85149,z=19245..33893
off x=5654..11498,y=56328..89517,z=-51989..-33158
on x=-20574..-5577,y=39609..41373,z=66022..82822
on x=-16635..-2094,y=61755..97252,z=-10151..3379
off x=-61710..-29756,y=-53529..-20524,z=50061..67887
off x=12337..45140,y=60042..89297,z=9701..36968
off x=-42381..-17258,y=-40434..-12651,z=-79807..-52351
off x=-57645..-52169,y=-20403..4163,z=-62673..-54906
on x=26686..40465,y=7785..22540,z=72481..83980
on x=-23030..-18498,y=-31032..-9833,z=61054..83029
on x=-10867..9838,y=45397..66784,z=-51464..-39505
off x=56847..77259,y=-17184..2949,z=-55341..-38773
on x=15524..40419,y=-42588..-27508,z=61847..79655
on x=-91271..-71952,y=15556..34300,z=14005..28676
on x=65780..81595,y=-29919..-17998,z=28053..44908
on x=31479..58997,y=55159..82009,z=-20523..11865
on x=2149..19762,y=-86184..-56666,z=18206..36344
off x=27069..56637,y=-73675..-53032,z=-13508..15432
on x=67416..85446,y=2917..28648,z=5402..35606
on x=-44500..-23236,y=-91223..-65053,z=-3525..14263
on x=-75739..-51755,y=49292..67356,z=-23308..10605
on x=-34841..-9806,y=-19491..-1709,z=64409..96498
on x=9551..24535,y=65245..79434,z=-24616..-12986
on x=-83205..-55438,y=-39820..-19718,z=22074..38142
off x=-71953..-53073,y=-44959..-30448,z=34060..50956
off x=-48764..-35469,y=-61736..-43279,z=41195..52261
on x=15917..37063,y=-75662..-56956,z=18898..36595
on x=37396..54561,y=-29290..-16200,z=64044..76199
off x=-14179..10592,y=-80049..-51222,z=38386..68137
on x=-29902..-21453,y=-94461..-71699,z=-6448..6244
off x=66863..74181,y=9066..35219,z=-28995..-8750
on x=7191..37647,y=-74506..-52303,z=45114..65447
off x=53433..79524,y=21402..48649,z=5035..16962
off x=54924..71855,y=28434..48319,z=-27603..-14643
off x=44568..73341,y=41377..69060,z=2132..18323
off x=32192..46654,y=-86893..-59876,z=21008..38923
off x=-26751..-3856,y=21442..39353,z=-84098..-58106
off x=63303..65533,y=42998..54340,z=3302..15908
on x=4235..13687,y=-50180..-34351,z=-76521..-58485
on x=-33290..-9251,y=40469..57296,z=-66106..-48947
off x=-81172..-62578,y=6482..36668,z=-45865..-22894
off x=-81904..-65892,y=-11941..4053,z=-42478..-22147
off x=35829..70381,y=41448..69602,z=18749..38582
on x=-10433..-2099,y=-82602..-51316,z=36823..64092
on x=38080..53913,y=36937..47688,z=39322..71479
on x=-21560..-4521,y=66563..85082,z=20252..45582
off x=-85857..-68417,y=-41847..-28573,z=-7729..2847
on x=-68327..-31793,y=-21900..-289,z=56789..69398
on x=-67562..-42688,y=16743..32262,z=22000..44570
off x=48052..67704,y=-23423..4103,z=44261..78217
on x=-22576..-194,y=61895..82600,z=-40620..-5831
on x=-16931..7379,y=-15102..1748,z=-87988..-74150
on x=-26047..12491,y=55107..74563,z=21205..33348
off x=-25435..-946,y=-82352..-52608,z=33364..53843
off x=-5833..18798,y=39831..56611,z=-72213..-47388
off x=-5822..14115,y=-98135..-64976,z=-20248..9788
on x=-15154..670,y=-75227..-54455,z=33215..60140
off x=18909..48180,y=62835..69076,z=27175..44519
off x=-58838..-51811,y=-8942..14922,z=-72422..-48233
on x=47362..82935,y=-58723..-33218,z=-14356..7150
on x=-64609..-42063,y=-58790..-35608,z=-50387..-39455
on x=9832..20482,y=40076..58832,z=41495..59344
on x=-29810..-7444,y=-73368..-47276,z=-64805..-37263
on x=-66021..-35774,y=44614..81545,z=-2880..20810
on x=30417..44347,y=64937..66634,z=27916..47000
on x=14925..33804,y=-59990..-48743,z=-55335..-46081
off x=-45330..-16788,y=-2912..25446,z=-78240..-63474
off x=-75837..-58168,y=-7970..3635,z=30476..60250
off x=-12011..13258,y=-89694..-69437,z=23137..41026
on x=58141..91626,y=-3240..13201,z=23976..30297
off x=-69440..-42294,y=-3341..11023,z=-75797..-55367
off x=28775..48112,y=49087..66505,z=-47634..-19480
off x=17405..40878,y=-78515..-63319,z=20589..35237
on x=46505..79525,y=46254..52587,z=-16956..-979
off x=14778..49904,y=51599..61793,z=-68550..-48309
off x=-17127..-2237,y=-80624..-47506,z=-43373..-23646
on x=42852..55498,y=60931..70121,z=-913..10924
on x=53866..67942,y=10584..28056,z=44574..51590
on x=52164..61481,y=25073..45284,z=20579..54644
off x=-38817..-3710,y=49963..73191,z=35577..68161
off x=74571..87380,y=-26549..-8365,z=-41849..-15478
on x=-11635..-3471,y=-2190..2324,z=-84076..-75086
on x=-87133..-75239,y=-9635..11698,z=-1887..26028
off x=-65700..-58148,y=-27843..-17147,z=46837..51188
on x=-8973..19499,y=-57314..-31198,z=-82041..-63223
on x=-8234..7290,y=72201..85190,z=-41415..-12525
off x=-69515..-63879,y=-11878..12202,z=-61049..-31131
on x=-593..25155,y=71211..88034,z=-13360..13827
off x=-41118..-22761,y=-51023..-43558,z=42131..56647
on x=45695..64697,y=-70454..-47486,z=4653..27783
off x=-69391..-49194,y=-6224..21792,z=-56102..-46702
on x=12567..16989,y=63359..83739,z=-7433..18488
on x=-47607..-28894,y=-76890..-58285,z=16882..41914
on x=-30015..4988,y=14737..22104,z=62453..85467
on x=-54404..-44808,y=-50918..-32444,z=-49452..-43588
off x=12954..44089,y=-28041..-5913,z=67605..87219
on x=-82272..-53812,y=25783..42439,z=-42516..-12409
off x=-94480..-60573,y=-25004..-2471,z=-2718..11057
off x=51649..65225,y=-14724..6310,z=38450..66205
off x=69856..80286,y=21304..46173,z=-11935..15518
on x=-77660..-69829,y=-25072..-3423,z=25500..50923
off x=37047..59725,y=51835..79489,z=272..35097
on x=-67713..-31489,y=35835..38541,z=-57246..-47586
on x=-18556..-7707,y=-17678..-8114,z=-87728..-59085
off x=-78610..-61520,y=11250..38454,z=-8429..3203
off x=-44797..-21166,y=-14536..9531,z=59712..82290
off x=45719..59834,y=-18760..-4920,z=-52363..-46018
off x=-35717..-12687,y=-83577..-62558,z=-8962..21313
on x=44536..59941,y=29580..64623,z=-24759..-4916
off x=-18864..-3108,y=48226..78222,z=42732..67354
on x=12357..39639,y=-44392..-26900,z=-82899..-54317
off x=-58310..-24651,y=15307..42877,z=-77149..-40022
on x=-43945..-20285,y=70712..82950,z=-4121..3442
off x=7101..22967,y=64872..83707,z=-25824..-9526
on x=-62076..-43190,y=-21347..-3360,z=-63874..-36231
off x=6340..27337,y=-73151..-47585,z=46269..52581
off x=47397..57486,y=-63732..-40590,z=44295..49537
off x=-78613..-57237,y=-56534..-32459,z=-35285..-13648
off x=-31072..-7685,y=-38542..-7098,z=57760..83347
on x=-63099..-35927,y=-77355..-53793,z=29264..33129
on x=-3649..25126,y=4399..19136,z=-90001..-77851
off x=8510..11246,y=57072..89213,z=11594..31605
off x=-16380..3546,y=28043..58308,z=62410..70708
off x=-73518..-51371,y=8803..36830,z=27148..50003
off x=-76901..-55804,y=-20544..-14756,z=-34886..-16018
on x=42245..58590,y=-60103..-37286,z=-38862..-20729
off x=2872..20494,y=76096..89070,z=-30072..-13378
off x=62225..70240,y=18398..51759,z=-26426..-10316
on x=-8268..25701,y=-44287..-22096,z=-73605..-62816
on x=12693..28817,y=-90968..-58755,z=-38493..-10212
on x=-72781..-51700,y=-59730..-40159,z=-22471..-10811
off x=-86186..-61431,y=-40796..-16811,z=-20606..1945
on x=19756..40482,y=41370..75797,z=22120..46137
on x=-38689..-13316,y=-24252..-16211,z=66862..80344
on x=25358..46927,y=-81264..-64854,z=29512..35413
on x=-16755..18260,y=-75084..-53865,z=48791..62218
on x=37799..45278,y=38376..53913,z=31553..51525
on x=-78288..-65705,y=-20882..5515,z=-56620..-32490
off x=-14779..-3865,y=-35491..-12433,z=60969..77610
on x=1041..7426,y=-75565..-54588,z=36056..52921
on x=-41864..-34775,y=22219..51820,z=40842..71780
off x=-23755..2275,y=51063..64402,z=-67945..-44438
on x=-93770..-74301,y=-30533..2469,z=-4612..7196
on x=-59566..-38442,y=-68259..-32849,z=36360..51994
on x=43187..57027,y=-18906..-8453,z=-77163..-57489
on x=-29794..-6913,y=28460..55404,z=-79855..-58015
off x=-57236..-52204,y=-21814..-7565,z=38317..74160
off x=56146..75194,y=-39180..-18839,z=-56810..-31930
on x=-66300..-58204,y=-19301..-4228,z=-61589..-39254
off x=-73278..-68405,y=22614..43899,z=-16199..-10518
on x=57074..79996,y=-6578..17919,z=33160..54010
off x=-40719..-2100,y=65789..80371,z=34406..44030
on x=-44080..-27053,y=2572..27247,z=51202..87551
on x=-25151..-7880,y=-60771..-53496,z=-55535..-47740
off x=-14214..11970,y=-4404..16997,z=-90900..-64733
off x=16310..46047,y=55884..79489,z=-14464..20211
on x=51594..75047,y=26992..37723,z=-11584..-911
on x=-45309..-20784,y=44096..70601,z=-52394..-33571
off x=16870..35569,y=13219..31860,z=69493..87370
on x=-22983..-16966,y=59778..70013,z=26803..46876
on x=33076..50573,y=-80935..-61509,z=-30866..-2196

5
inputs/day23.txt Normal file
View File

@ -0,0 +1,5 @@
#############
#...........#
###D#D#C#B###
#B#A#A#C#
#########

252
inputs/day24.txt Normal file
View File

@ -0,0 +1,252 @@
inp w
mul x 0
add x z
mod x 26
div z 1
add x 10
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 2
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 10
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 4
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 14
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 8
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 7
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 14
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 12
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -14
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 7
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x 0
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 10
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 10
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 14
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -10
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 2
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 13
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 6
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -12
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 8
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -3
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 11
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 5
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -2
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 11
mul y x
add z y

137
inputs/day25.txt Normal file
View File

@ -0,0 +1,137 @@
>.v>.v...v..v>>.>.>...vvv>>.v.>.v>>vv..>......v>.......v.>>..vvvv.>..>>.>.>vv...vv>..........>..v...>v...v.vv..>v>.v.v>>v.>vv.v.>.vvv.>v.>.
v.v>>..>v>>.>>v...>>v>v>..>v.>.......v.>..v>>..>>.>.>....>.>>vvv..>...>>>...>v>...>>.vvv...vv..v.v..v.>..v>v...>..>.v.>.>>v>v>vv.v........v
....>.>vv>.v>>.>>>v.v>vv>>..v..v>..>..v......>....v.>vv>....v>>.vvvv.>.>..>.vvv...vvv.v>...>>......v>>.v.>v>.>v>..v...>>.>.vvvv.v.v.vv.v.>>
...>..v.v.....>vv..vv.vv.....>.v.>v.v.>>..>v.vv.v.>>v.>.>..>>>>.>vvvv>.v.v..>..vvv.......v.>.>v>vv>>.v.vvv..>>>>>v>.....>v...v>.vvv.>v...v.
..>.vv.v.v>v.v..v.v...v>v>v.>.v.v>v>.>>..>>v.>..>.>.......v>v..>...>.>.v..>v..v>vv>..>>>....vv.v....>.>..v.v..vv.>.>.v>>v..>>......vv.>.>v>
.>.>.>.>>>>v..>.>.v>vvv.>v>..>v>vv.>v>.v...vv.>...>.v>.>>v.>v.>>.v>.>..v..>v>>...>.>.v>..>.v>>vvv.v.v>v>.>..vv....>.vv..>>v.v..vv..v.>.v>..
>..>.>v>>v>>>>....v....>vv......v>.v.vvvvv.>..>v...>>v....>>v>>>>>.>>.......v..v>...>.>.v.v.vv....>>>v.>..v.>vv>...>v.>v>v.v..>.vv.>..>..>.
v.v>>>.vv..v.v.>v>v>>>......v>.v.>v..>..>>>.v..v>.>..v...v.vv.....v.v>>.v..>..>.....v>....>>v.vv>.......>.>v....>>......v>.>.>.v.>.>>..v...
>.v>..>>>..>..vv.vv>.>.>.>>vv.>v>>v.v>..>...v.>..>..........v..v.vv.>..>..>.v..v...vv..v>>>.>v....>..>>....>>>..v.>....>..v..>...>>.v.>>.>v
>.>..v.vvv..vvv>.v..>v>>v>>.>.>..vv..vv>>v....>.v.>vv>...>..v....v..v..v..>v>.....>>vv.v.v>.>>...v.>..>vv....>.v.v.>>...>..>>.>>>>>>>.v>>v.
v.v>>..vv>.v.v........>.v.v....>.v.vvv.>v>..>....vv.v.vv>.>v>v....vv.>v.v..>v.v>>...>>vv..>.v.>v.>v....v...v>vv>.>.v..>.v.....vvv>>..>...>.
.v>v.v>..>v....v.>v>...vv>v..vv.v.>>...v....v>>.v>v>>>.vv>>.vvv..v...v>....v..>..>vv>>v..v.v.>>>>>.vv..vv...>..vvvvv.v.v>v>>..>v.v.v>..>>v.
..v.vv>..v.v.>>..>v>.....>>.>v..>.>v.v.>vv>>>vv.>.v.>v>vv>>v...v>vv>>.>v>v..>.v>v>>..v>..v..v>v.vv.v>>.>v>>..>>vv.v>..v>v>>.v.v..>.>.v..vv.
>>.vv>....>v.>v.>..>....v.>..v>>..>....vv..>.v>.>>..>.v....v.>v>v....v.>>.v..vv.vv.>..vv>.vv.vv>v.v>v.>..v..>.v>v...v...vvv>....vv>..v>.>..
.v.v>>>v.....v...v..v...v.>.v...>>.vv.>>..v>..>v.v..v..v.v>.>>...>>....>..v>.>v.v.v..v.>>vv..v.>...>>vvv>v.vv.v.v..v.>.v.v>...>>......v..>>
v.>..vvv.v>>v.v>>...v..vv.v.>.>v..v..>v.>v.>>v..v..>..v..>..>v>v.....v.v>.>v.v.>>>.vv.v.>>..>..v..>v>>....v.vv>>v>>v>v.>v..>>>v>..v.vvv.>..
...>..>>.v....v>>..>.>v...v>>>..>....vv.v.>>...>...vv.vvv.v...>..v..>..v>.v>v.vvv>>v.>.vv...vvv>.>vv.>.v.vv...>.vv.>>>>>......>v>v..v......
>...>...v.vv.>v.>>>v>>..v.v.v>>..>>>..>v.>>.>v.v.>v.>.......>.>>>...v..>>..>..>.>>.v.v>>vv.v>.v.....>>...>....>>......v>......>v>.>...>>.v.
...v>v>..>...v>v.>>>vvv.v..v.vv>.v>..v>.v.v..vv.>v>.v.vv.>...>v..>...v...>v.v..v....>v>>..v...>..>...>...>>.v.v>.>..>.vvvv..>>>v.vv.>v.v>v.
.>...>>....v...>>v>v>v.v......v.vv...>.vv.v.>..vv>.v..>..>.....vvv.v..v.>...vv.>>>vvvv.>v>vvv...v>.v.>v.>.v>>.v.v>vv.>..vv>.v>v>>>v.v...>v>
..v..>v>.v..v..v>v.>v.v.>v>...>>v..v......v.>>>>.v.>.v.>v>v..>>>vv..>...>.....vvvv..>..>.>>>...>>>v>v..>...v.>....>.>...>.>v...>..........>
>.....v.>..>.>>......>vv..v>...v...>>..>.v>>v....v>>...v>......v..v...>...>.>v.>.vv.>....>...v..>>>..>.>...v...vv.v..vv..>...>....>.......>
v.>...>v....>..>>v.vv>.>>>..>vv..v..>>....vv...v..v.v..v>..>>>.>.v.>.v.v>..vv..>>.v.......v>.v.vv..>>v>>.....vv.>>..v>.>>v>...>vv>v>>v..>>v
v>.v>.vv>>.>..v..>....v...v...vv>......v.v>v.>...v.vv>..>v.v>v>.v.>>..>>.>.vv>v.v.>.....>.v.>..v>.....vv.>>..vvv..vv.v..v>...>..>..>vv.>..v
v>.....>v>>.>vv.vv.>>v..vv.>vv>v.vvv..v.v.>...v..>>v>.>vvvv.v...v.>.vvvv.>.v.v...v.>....>vv>..v..v..>....v.>.....vv.>.v.>.>.vv>vv..vv>v>>>.
>vv..vv.>>.vv....v>>vv.v....v>>v.>>.>...vvvv..>.>v..v.v.v.......v.....>>>v..>.v>v>>v.>....vv>>.>v....vvvv.>>...>.v.v>...>>..vv>....v..>>v..
....>...v>vvvv...v...>v.v...v.v...v>v>...vv....>>..vv.>....>>.vv.>.v>.>>v..vv>.v.>.>.>>.>.....v...v...v..v...>.vv.v....>.>v>.>.vv>>.vv.>>..
.vv>.>...v>...>v>.vv>.....>.....v.>.>.>.>.vv...>v.>.v>.vv.v.>....v..v.>.v>.>v>v...v>.v..v.v....>.v.....vv..>vv.vv.>..>>...>.>..>.....>..v..
v..v..>.vvv>.v.>vv.....>v.v...v.>.v.v>v.vvv.....v.>.....vv>...>>...v>>.>>..vvv>..v>>..>.>v>.v>v..v.>...>>v>v>.v.v..v..>v..>>.>..>.....v...>
v.v.v..>>>....>.>>>v>>.v...>...v.>.vv>>..v.>..>>>...v..>v>..>>.>..v....>vvv...v>v>>>..>..>v>.>>>..vvvvvv.>vv.v...>.>v..v.>v....v.>..>.v....
>>>>..v>v.....>.....>.v..v...>>....>...v..v...v>v.v>>....v...v>.vv>..>vvv.v..>vv.v...>......>v>>v..>...>....>........vvv>>.vv..>>.v..>>v.v>
>v...>v>>>...v>.......v>v.vv...v.vv..>v.>.>vv>>vv...>vvv>...>.v>.>..>..>...vv.>>..v..>.v..v.v>v>>..>...v>v.>.>v....vvv...>v>...v.v..>..v.>v
>.v.v..>..v.>.>.v.>..v..v.vv........>>vvv>.>v.v..>v.>..v.>..v>>....v..vvv>v..v>>>v>>...>.>>v>vv>....>v...>.>.vvv..>..v.vv.>....>..v..>.>>v.
>...>v..v.......v..v..>v...vv.vv....v>vvv>...>>.....>>vv.v.v...>.>.vv>>>.>..>>>..>..>.>v.......>vvvv.>.>vv.v>..>v.>.v..>.v...v>v>.>.v>...>>
vvv.>>.>v>....v>.>.>>v.vv...v.>>>>.vv>v>.>vv..v.>...v>>.v>..v.>v>..vv.>>vv.....v.>v>.>....v>....>vv.v.>v....v.v>>.>.v..v..v>.>>..>.....vv.v
>>v.>>>...vv.vvv>>.>v>>v.>....v.>.>>v>..>.vvv..>v>.>.>>.vv..v.v>>v.>.v>v>>.v>.......>v>.>>>.....v...>...v>..>..v>vv..vv.>.v..>vv>..>vvv.v..
>v...>v..v.v>>.....>....v>v..v>v.>..>.....>>..v>.>v.>.>.v>.>.v....>v...>.v.v.>vv.v.v.v..v>..v>v>..vv.v>...vv.v.vvvv>.>...>v...........>....
.vv.>v.v.>>>>v..v.vvv>...v..>>.>v.>>v>>>.>v>.>.v.>...>..v>>>.....>v.v..v>.v..>.>.v>..v.v...v.>....v..vv.>>..>.vv>.v..v..>...>.>..>>vvv.v>>v
.v.v>v.v.v.vvvv..>...v.vv.>vv..v>vv>>>..v>.v.vvvv..v>.>....>...>vvv>>>.v.>v>v.vv..vvv.v.v>.v.......>...>vv>v..>...>>...>.>v>>v..v.>....vvv>
v>.v........vv>.v.....>.v...>.>..v>.........>.>.v>>....>>.>>..>..v.vv>>v...v..>v.v...v.v.vv.vv.....v>.v>>v.v>v>>>....>v>>>>v>v..v.>vv.vv.>.
>vvv....>...vv.>>..v>>>.>>v....>...>.>vv..v>v.v.>>.v>.vv.>v>>.>v>....v.vv.v...v>.v.v>..>...>.>v>...v.....>v.>.v>....>.>.>.v.v>v.......vvvv.
v..vvv...>>.v....vv.>.vv.v..v.vvv.>>>>..>>..>.....>v...vv.>.v.>vv...v>..>v...v....v>vv.>.>v..........>v...v>v..v>v..>.....v>.v>..>v......v>
vv.>.>vv>v..>v>.vv...>.vv..>.v.>>>.>....v>v>>>>..v>....>vv..vv.>.v>.v.>...>.v.v>v>v>v.>..>v......v.vv>..>.>..>..>.v>vvvv.>...vv.>.>vvvv>>>>
>..v...>v.vv.>>vv>>.>.>....v>...>v...>....>..v.....v.v.>>>>.>.>.>>.>.>..vv.>>vv..>...>>>.v....v.>>.vv..v>.>>>.>v..vv..>>>.>vv>>.....>vv.>..
>.>>..vv>.>v.>>v...>..v>...>..>.>v>>v.v.....>.>..>.>v.v>.....vv>v>v..>v......>v..vv...>>>>>..v...>....>....>v.v>..>v.>.>.>.v.vvv..>>.v>v.>.
>....v>>v>...>v.vv>>v..>>..v....>vv.v.v>.......>v.v.v.>>.v>vv>>..v..>...>.>......>>..>>.>....vv.>.v>>....v.>...vv.v>.>.vv.......vvvv......v
.>..vv.....v....>>...v>.v.>>.vv..>.v...v.>>v>>>>vvvv....v....v.vv..v.vvv>>..>...>v.....>....>....v>v...>..>>..>..v.v.v...>>>.v.vv.v...v....
..v.vv>.v>.v....>.v..>>>>v>.>vv>.....>v..>....v.>.v...>.v>>.>..v>v>...v>....>>.v..v...v.....>v.>...vv>>.>..v>.vv>v>v>...>>..vv.>..>.v.>.>..
..>vv>.vv.v>v>v>.vv..>>>>..>>..>v>v>vv>.>.v>v.>>vv.>..>.vv.....>..>>.v.>..>.v.>.....v.v.vv.vvv..vv....>....v>.v...v>.>>v..v...vv.>...>.>.>.
.>>>....>vvv......v>...>v.>vv.v.>>vv>.....v.v.....v.>.>.>..>>.>vvv..vv>.>>...v>..v>.>vv>>......>>.v>..vv..v..>v>v>.>.>.>>..v..v....vv.>.v.v
.>.v..>.....v>v>>.>.>.>>>v>v..>....v....>>vvv.>>...vv>>v.v..v.>.>.>v.>..>>>v...>vv>.v>.vvvv..>.>.vv>.v..>.v..>..vv..>>>..v>>.>..>.vv>v.>v..
..>v>>.v.>.v>>v>v..v.vvv.v..>>>v.vv.....v.v.>.vv>.>vv.v>.vvv..v.>.v.>v.vv..v>.>.v.vv>>...vv.>v.>.>.vv.>v.vvv....vv.....>...v>..v.>v.>v..vv.
>.vv>.v>...v.vvv...vv.v>.vv>.v>vv>>v>>>>....>..v..v...v>v.>..v..vvvv>>v..v>v.v..>.>v...>...>v>>v.v.v>.....>v.v..>..vv>...>>.>...v.v..v.....
..>vvv.v>.>>v...v.>>v.>vv..v...v.>.v>.>v.v...>>...>.>>.v....v>v....>.>.vv>>.v>v.v.v.v..v....v.>vv>...>..v>>....>v..v.>v.>>.>.>.>.v.vv..v.>v
..>.......vv>v...>.>.>........v..>.>..v..v..v.>>.>>.v..v.>.>.>.v..>...>v.>v..>..>.v>>.v.v..>..vv.v>.>..v.>v>...>..vvv.v.v.vv.vv>>.v>>..>...
v..>v....v.v>.>.>v..>v...>>.>.v>>>>v.v>>vvvvvvv.v.>vv.v...>v>.>..vv..v..v....v......>>v..v..>v...>.vvv.>...>v....>.v.v..>..>...v.>...v.vv>v
>....v>.vv.....>>v.>>>>>.>.v..>.>v......>>>.>>...vvv......>.>>....v.>v.>..v>>>vv.>..>v>>....>.vv.>...v...v.v..>vv.>..v...v>.>v>.>>.>>.....>
>.vv.v>.....v..>v...>..v....>>...v>......>>v>vv>...v.v....v>v.vv.v.v>...v...>....v....vv..v.>...>.>.>>>......vv...>v>vv.v...>v.v>..>..v...>
vv>.v.....v>.vv>>..>..>.>....>>.>.>v...>>vvv...v..>>.v..v..>>v.v..v>>.>.v..vvvv.>vv>>.>....v.>..v>...v>v..>>v.vv>.>..vvv...>>.v...v..>..v..
>>v....>>.....vvv...v>v.....v...>>>>...v>...>>>>v...v.v.v.>...>vv.........v..v>>v.v>v>.>>>>>.>vv...>..v.vv.v>..>.>.v.....>>v..>v>v.>v.>v>.v
..>......v.....>vvv>....>>v>v....v>.>v.>v..>vv.vvv...vv..v.v.v.>...v.v>v.>>>....vv..>v...v.....vvv..v>.vv>v...v>.v.vvvv....>.>v.>v.>vv>vv..
>v...v.>....>.>.v...>>v>..>..>..vv..>.>>vv.v>.>>..>.v.....>>.>>v.v.>vv>v>.....vv.>>v..v>...v>v...>...>.v>..>>v>.>>vv>v>.>.v.vv.>>>.>v.v..>>
>.v>>.v.v>v>.>>..v>>.v>.v>v.v>....vv.vv..v..>...v.v>>..>vvvvv>.>.v..>>>..v..>>..v...v...>v.>.v.vv>.v>..>..>>.>.>.v.v..>v>.v.v>>v.vvv...>.v.
....>.>...>vv.vv..v...v.>>>...>vvv>>.>.v.....vv>vv.>v.........v>v..v..vv.>..v>v.>v....v.>..>.....v..v>>>.....>.>>>vvv...vv>.v..v..vv>.>..vv
v..vvv.>.>>....>v..v..v..v>>...v...v.>.v.>>.v..vv..>vvv..v....v...>.>>vvv>..>v.v.vv.vv.>.>.>vv..v>>>v.v.>......>.......v.v.v>.>v.....v.>v..
v.vv.v.>>.>v.>vv>..>.v.>>v>.>v>.>.>v>.>.v>>.v..>........v.v..v..>>.v..>...v.v.>v>...>v.>.vv..>>.>v....v.>..v..v...vv..>>v..v>>vvv..v.v...>>
>v..v>>v.>.>v..>v>..v...>...>v.v.>>..>v>.v>.>..v......v...v>>.>..v..v..v.>>....>>>>....>>....>.v>v.v>.v..>.>v>.>.v.v...v>...vv>>>..vvv>.v.>
...>...vvv>>..>>.>vvv.....vv..v.v>.v..>>.v>>>vv>>v>>..v.>..>v>>v.>v.>.v>>vv>vvvv>.vv.>>.v....>..vv>....>>.>v>..v.>..v>......vv.v>v>.v>..>..
.v>..v>>..v.vv.v..v>.>.v..v.v..vv.......>.>...>.>..>v.vvv...v..vvvvv.>>.v....v.>v.vvv>v>.>.>..v.vvv..>..>>v..>....>....>v.>...v...vv..>v>v.
vv.v>...v>>.....>v>v...vv>.>.>>.vv..v...v.>.>..>.v.v>>.>..>v...>.v..>.v>.v...>...>.>vv..>vv....>.>.>.>>.>.>>>>.v..>.vv...>>v..>vvv..>.>v>..
>..>v>.>v.>vv.>vv.v.v>.>.v..v..>v>>.>..>..>.v>.v.v.v>>..>....>>.>>>v.v....v.>>>...>v>v.>.>.v.vv.>>.vv>..>.v........>v>v.>..>.>.>>v.>..>.v>v
..v>>>>v.>vvv>...v..>.......>.v.>vv>v....>.>>>..vv.>..>>v>>v>.v>...v.>...v.v>v.....>v>.vv.>>>v>..vv.....vvv..v.>.>.v..>.>.v.>..v>......>.>.
>.v..>.>..v>vv.v..vv..vvv>>vvvv..>v>v>v>v...v.v>>>>v.>>v.>v..>vv..v...>v.>v..>vvv.vvv..v...vv...>.>>v.v.....v..v.>.vvvv>v..>v.>.v.......v..
v.v.v.v.v>.>.>v.>.v>>vv.v.v>.>.v>>..v>>>....vv.>...>...v.vv>.>...v..vvvvvv.v..v.>.v>v>v..vvv........>..>>...>..vv>v.......v>>v..v....v>.v.v
v..>>.>..>...>.v>vv...>......v>.>..>v....>v....vv..v.>>.>.>>.......>v..v.>>.v.v>..>.v..>v..>.>.vv>.vvvv>.v>.v>v.>>v.v>v>vvv...v....v>v>.>>.
.>>.>v.v>..>.>v........v>.v.v.v>.........>v>.>>v..>vvvv.>v.>>..v...>.vv>..>....>.vv.vvv.>>>..>>.v>v.v>.>.v>....vv...>v>>.....v.>..v.>.>>>v.
>v>>.v>.v>v...v..v..v>>...>.>>>..>..>...vv.>v>>>.v....>>.......v..v...>.v..v..v.>vvv.......>vv>v.....v..>>v..>.>vv>>..v>.v..>..>.v..v.vv>.>
v...v>v.v.>>.vv.>>...>...vv>....v.v>..>>..>>>...>>.>..v>v.>v..>..>.v....>.>..>.....>.vvv.v..>...v..v>v..>.v....v>.vv>v.v>.v.>.....v....>..>
v....v>.v..v>v>.v>vv.>.>v>.......>......v>.v.>..v.>...>...v...v.v.>...v>>v>.v.>v.>>...v>v.v.v>...v>v.vv.>v..>>>.>v>.>v.v.v...>.vv..>..>.vv.
v....>.v>..v>.v>.>..>..>.>vvv>>.v...v..>vv..>......vv.v..>>...>>.>>..>v...vv..>.v>.>v>v.>.>>...>.v.v.>..v>>>..>.vvvv>..v.>...v.>.>..v>.v...
>.vv>.v.>v....vv>.>>.v>>v....v.>v..v..>>>..vv..>.>>>.>>.>v.>>.v>>..>.>>...>.....>.>v..>.......v..vv..>>v.>>...vv>>.v.v>....v.v>>.>>..v>v.v.
>v...>>.....v.vv..v>.vv..>.....>....v.v>..>>...>..v..>>.v>>.v>v.v.vv.v>....v....>>.v>....>>vv......>>.v>..>.vv.>..v.v>.v>.vv.>...>>.....>vv
v>v...>.>.>....v.vvv.>vv>.>.>..>>v....>v.......v...>v.v.v...>v>.>.....>v....>.v..v.v.....>.vvvv.v.vv>.v>>...>...>..v>>>>...v>>.v..>v..v>...
..>>v>>vv..>.>>.>...v>>>vvv>v..vv.>...vv..vvvvvv.>>..>v..>.>>>.v.v.vv..v.v.>.......v>.vv...v>.v......vv>v.>v.v>.>>>v...>>vv>.>.>....v..>v>>
..>v.v..v>..v.>vv>vv..>.v.>v....>....v..v>>v>.>.vv....>v..v>..v..v>.v>.>>>>>.....>>.....>>>v.>>.v>..>>vv..>>>v.v.vv..>>..vv...>>.>>...>v...
..>v....v.>v.v.v>.>>v.v>...>>v.v>...v.v...>vv.>>..>>......v.>>vv...>.>....>v>.v...v....>.>.vvv.>>>v..>>vv.vv..>v.....>>....v>>v>.....>....>
v........>v..>.>vv....v.v>>.v>.>>v>.vv..>...>..>v.vvvv.v.>....>.v>>.>v>>>.v.>.>.....v.v>v.v>v.v.>v>..>v>>v..vv>>>..v..v>>.>v...v>...v..>>v.
.>..>>.v.>v......>.vv>v>.v.>.v.v..>>..vv...v..v.>>.v>.v>.....v.>..>.v.>v>.>..>v.v...vvv..v..>.>.v>vv>.v>....v>.>v..v>v>>>.vv.....v...>v>>v.
.....v>..v>>>v.v..>>vv.v..v>.>...v..>.v.>>>v.>.v>.v>v>.>>..v.....v..v>vv.>>...v.v.v.vvv>>>>..>vv..v>....>...>>.>....v>.>>..>>....vv>.vvvv.v
.vvv..>.v>vv>>>.>.v>..>>.>..>.vv.>....>.v..v>vv...vvv..vvvv.>.v.v.>>vv>..>>........>>..v...>.vv...>v>.v.>v.v.>..>.v>>>>.....>.....v>.>..>.>
.vv.>>vv.v...v.v...>v>>>>v..v...>>......vv.vv...>v..vvv.vv.v...v.v>....>v.v.v.>....>...v..>v...>v>....v...>....>.>>.>..>>v>.v>v....>..vv.v.
v>.v.>v...vv.>.v.>.....>.v.vv.>>.>....>..v.v.v..v>v.v>vv.>>.>v>.>....v.>.>.>v..>.vv..vv....>.v.>..>vv.vv>>v>...>v>>>v>...>v.>v>.v>.v>.v>v..
..>>>.vv.v..>.>..>....>...>>>.>..>>>v..>..v...v>v>.>.vv....v.v......v.>.>>>.v.v..vv.v..>.>..>>.>>...>.>>..v.vv..v>.>vv..v>.>vv.>..>.>..>...
..>.>...vvv.v.v..>.v.>>v.>v>>....>..>.>.v>>vv>.>>.v...>...vv>>>vv.v...>.vv..v..vv>..>v..>.>.>.>.>v>>.>..vvv>.>v....>v....v>>>............v.
v.vv.>..>vv...v.......>......>>>v.v>.....>.v>>.v.>..........>>.v.>.>..v>.v.v...>..v>.>>>>v>..v>v.>.>...>.>....vvv.....vv.v..>.......v>v>.>>
.>.vvv.>.>vvv...>>.>v.v...vv.v.v>...v..v>>v.v..v.>>vvv...v>>>.v...>..>v..v>>v.>v.>.v.v..v>v.>...vvv..>v......vv>>>>.>>.....v.>>>v.vv.>..v.>
.vv...>>>..vv..vvv....v>v.v>v>v.vv.>>vv.>vvv>..>...vvv...v.>.>...>...>........v.v>.v>>...v>...>>.>v.>...>.vvv>...v>..v...v.>v>>..>>..v.>v>.
.....>>.v....v..v>vv.>..v...>vvv>..>....v>..>.>..>v.>v....v>v...v...v..>...>>v.>>.vv..v..>.v..>.v.v>v>vv.>.>vvvv...>.v.v.v....>>v..vv.>>.>.
....v>.v>v>.>.>.v>.>...v>...v>>>...>>.>v>.....>>.>..vv..v..>>..>.>v.........>v....v..v.v>...>....>v.>v>>....v..v..>>v.>....>....>v.>..>.vv>
.>>.v.>.v.v.v...>vvv>..v.v>v..>v..>v...>....vvvv.v>>v.>>v...>..v.vvv..>..>>v..v...>v>>vv.>>..vv..v..v>...v...v....v...v....>vv>>.vvvv>.v...
..vv..vvvv.vv...>.v>>.>v>>>>>.v.>..>.>.v.vv>>.>>....vvv>.>>.v.>.v.vv>v>v.>....>v.......>.>.>.vv..v.v>v.v...>..v.>..v>...v>v>>>......v>..>v.
>.>>.v.v.>v>v.v>.>vv..>>.vv.>>vv>....>.v.....v.>v..>>>.>.>..v>.>v...v...v.>..>.v>v>..vv>..v.....v.>.v>.>>....v...>.v.....v>vv.....>>>v.v>.v
.v>.....v...>.>...v>v.v..v.>v.v.>>v>.vvv>.>.v.vv.>v>v>v>v>>.vv..>>v.vv>.v>>.>vv..v>..vv.vvv.vvvv>.>.v.>.>.>vv>.>...v>.v>v...vv>v..v>v..>...
...>..v.......>v.v.v>v.....vvv...v..>>vvv>.>...>..>.v.v.>>.v.v.>.v..vvv..vv>v>v..>..v.>..>v.>.>...v>.vv.>>.>v.>..v>v>....>.>.vv..v>....vv..
.vvvv.v.>.v..>.v.>v.v>>..vv...>>v.>>.>.>.>v.v.v.v>v....v..>v....>>.>v>v.....>.>..vv....>.vv...vvvv.vv.vv...vvv.>.v>v.>.v>..v.v>vv.>..>.....
>..v.v..>.>>.v>..>...>.>>.>>.>..>.>....>v.v>.>.v.....v>.v>.vv.v>...vv.>.vvv>>v>.>.v..>.>.v>v>.>..v..>.>......>>.......vv.>..>.v>vvvv..>vv.>
v....v.vv...>.v.v..>>.>....v>>........vv.>.>>...>.>...v..>.v>..>..>>v>....v.v..>..>v.vv.>.>>.v.>>.>vv>>.>v>.v>>>.v....>....>...v>>..v..v.v.
v.v.v...>>v...>>>.v.vv.vv.vv>>>.v.>...>>v.......>v.>vvv.>>.vv.......vv...v>..v>.>>.v..v>...>.v..vv.v>..>v...v.vv>.>>.v..>.v.>.>..>>.vv>...>
v..>vv.>v>.>v.>.>>>vvv>..v.>>>v>.>v....v.>v>.vvv>..v>....v..>>..v..vv.>...v.>.v......v.>.>.....vvv..>vv>.>...>.vv>....>>..v>..v.v..>>v..>v.
.....v.>>vv.v>>.>vv>.>..>...v>>..v>....>.v.>.>...v>..vv>v>..>..>.>......vv>.>.vv>.....v>...vv..>..>v.v.>.>.vv>.vv.vv>.vv.v>>>..>....>.>.>v.
.>v..v.vv..v.v.>v..>.v>>v>v.vvv>>...vvv.....vv..>.v>...>>>.v....v>>.>v>.v.vv>....>>>>..v.>.>.v.....v>>v..v....>..v....v>...>>v.>v>v...v.v..
.>v.....v..>.v..>...v..v.>vv.vv.>.>v.>...>...v>...v.v.>..>v..>..>v.v..>.v.v>v.>.v..v......>...v.vvv.v>>v.>.v.vv..>>v..v>>.v.>>.v.v>>>....vv
...vv.>v.>..v>>..v.>.>vv.vv...>.....>v>.....v..v..v.v.>>..vv.>v.>..v........v.v..>>v.>v.v..>...>v.v..vv>v.v.v>..v>.....v.v.>.v....>>>v>>..v
...>v.v.>...vv>.v.v.....v..v....>>..v.>v>vv>>.......>v..v.vv..>.>>>vv>v>>>.v....vvvvv.v..v>.v.>v>v>>..v..vv..v.vv>>v..>.>..>....>..>.>>.v>.
>>..>>...>..v>vv.>>>...vvvv....vv.v>.vv.>.v.vv>>..vv..>..>>>..>>..vv>>.>vv>>.>.>..>vv.>.>v..>>.>.v>....vv>v>..vvv.vv.>v.>v>>....vv.vvv...v>
..>>v>..>>.v>vv>....>..>>.v>vvv.vv..>.v>v..v.>>.vvv>.>.>v...>v.vvv.>.v.>v>v.>..>.v>>.>.>v..v..>v>>v>.v.>.>.v.>...vv...v.......vv.....>.v.>.
>..vv>>v...v>v.>vv>.v....v.vvv.>......>v.v>.vv>..>>>v....>>>.>...v>>>....>...v..>..v>vv..v>v...>vv>.v..v..v>.>.>.>..vv>>v..v>....>>..vv..>.
.>.>v>vvv.v..v.>v.>...v>.>v..>vv.>..v.>v>.v...v>.>>vv..........v>.v.vvv.>>>..v>vv.>>>v>..v....v..>..v.>>..>.>.v>v.v>.v>.v...v.>>.v....vv...
....>>.v..>.......>.v.v>>>vv>>..>v>v...>.v..v>.vv.v>>vvv....>vv>v>..vvv.>>>.v..>>.v.>.....>vv>>....v>vv>v..>.>...>.>>v......>..>v..v....vv.
.vv..>.>..>..v>...>v.vv.>..>v.>..v>v..vv>>>..vv..>vvv.....>...vv>.........v..>..v..>>.>>v.v...>>v>v>..v>>.v>.v..>v.vv>vvv>>>..v>.vv..>>.v.>
.>vv.v.v..>.>...>..>v>..>...v.>...>vvv.>....v...>..vv...v>...>vv>v.v..>v..>v.>...v.v>v.>.v>v>>>v>..vv..v.>>v>.v>..v...>v>>..>.v.v.>>..>.v.v
...v>..v.v..v>vv.....>..>..>>......v.v.>v.....>v.v...vv.v.>v>>>.....vv.>>v>>......v..v>v..vv>>v....v..>..>v>>>.v..>.>...v...vv>vv>v...>.v>.
v.>>v.vvv.vv.vv.>.>.v.v>v.v>..v>v.>>>..>v>.v....>v....>>.>>..v.vv...v.v....>.>..>........vv.v.>..>>.v.v>...v>v...vv.v>>.>v>>.>>vv>.v..>v>vv
v.>v.>v>.vvv.>v..>..>>>...v.>.v...v.>>.>..>>.v.>v..>.vv.>....>>vv>....>..>>vv>>....>v>.v..>.v>.>...v..v..>v>>>..v...>...>.>v>.>v.>.>.>.>.vv
vvv.>>v>>v>.>..v>v>..v>v.>>v.v...v..v.>vv...vv.>.v>>>vv>.v.>v..v>>.>>vv..v....>.>v.>>v.>.>....>>.>.v.vv>.vvv..v...>..vv..v......>vv.>>>v>..
.>.>.vvv....>v>>.>.v.vv.v>>.>>...>v>..v.>v.>>>>v.v>v.>v...>>>>>...v....>..>v.>>>.......>...>v.>vv.>.v.vv..>>......v.>..>...>.>v.>v>..v.vv>.
..v>..>vv.>v>>..v.>.v....v>.v>>v.v...>vv....v..>.>....>.>v.v.v.v>..>.>.>.v.>>.v..v.>>v.vv>>>v>.v..v...v.v>vv>>vvvv>.>...>v.v.v..>>>.v>>.v.v
.>...v>v>>..v.>>.>v.vv>.vvv>.v....v>..v.>.vv..>.>>.>.>v>...v.>v>..vv>.vvvv>.>....>..vv>.v.v..>v..v>...>...vvv.v>>>>>>..>.>.>...>..vv.>.v..v
v...>..>.>vv..>.>v..v.>>.v>>>.v>>...>.....vvv.v.>v..>..v..v...vvv.vv>..v>.>.vv>v...vv>>>v...v.>v....v.v..>..>vv.>v>vv.vv>>>..>v.>vvv.>v.>..
>v...v...>>.v.>.>>.v>>.vvv>>v>vv..>>..v>>.>..>.>v>>>v...v..>.>v..>....vv..>>.>>......>v>>>..v..v..>>>.>....>......v..>>v>>.>>...vv.v.>vv>v.
>.....v.....>v>.>.....>v.v.>.v>vv..>.>>....vv>..>v..v>.v...>.v.>v>v.>vvv..v>>v..>..v>>.>...>.>>.>..>.vv>>.vv..>>v>>.>.v.v.v.>vvv>v>>v>vv.v>
v.>..>v.v>v.......>v......v...v>.vv..v>...>.>.....v.>..>.>....>...v.v>v.v.....>....vvv>..>v.v.>vvv.v.v.v>>>..>v>.>.v>..v.v>.>vv.>.>.v.vvv.v
v...>.vv>.v..>.v>.....>>vv>.v..>>>v.>>..>.....>v...>>..v.>.vv.>..>..>v.>>>>>vvv....vv.>v..v>..>.v>..v.>...>v..v.>..>v.>.vv.>vv....>>v.vvv>.
>..>>...>.>.vv>..>v>..v..v>.v.>.>vv.>v>.>>..vv.>..vv.v>vv>v>.vv..>>>..>v...>.>v>v>>>.........>>>...vv.>.....v.vv>.>.vv>.....v.v..>...v.vv..
v..>>..vv..v..>...>>.>>>..>..>.>v..>..>.>.vv.>>...>.>.>v>.>..>>.vv.>..>.vvv>>....>>>>....>v.>>>>.>>..v.v.>vv..>..v..>.vv>v....>vvvvv>v....>
v...v.>v>.v...>>v.>.v>>.v.v...v.>..>..>>>...v.......v>>>>>.>.v.v..>...v.>v>v.v....v....vv>vv.>.>v>vv...v..vv.v.>>v..>.v.v.v...vv..v.>v>.>v.
.>v>.vv.v.>.>.>>v.>>...v.vvv.v>...>>.>>.>.v...v....>..vvv.>....v.vv.>..v...>>..>...vv.>.>v>v..>>>.v.....>.....vv.v..>.>>>v.vv>vv.>......>.>

283
src/day16.rs Normal file
View File

@ -0,0 +1,283 @@
use std::num::ParseIntError;
use std::str::FromStr;
#[derive(PartialEq, Clone, Debug)]
enum PacketPayload {
Literal(u64),
Operator(u32, Vec<Packet>),
}
#[derive(Clone, Debug)]
struct Packet {
version: u32,
payload: PacketPayload,
}
impl PartialEq for Packet {
fn eq(&self, other: &Self) -> bool {
self.version == other.version && self.payload == other.payload
}
}
type ParsePacketResult = Result<Packet, ParseIntError>;
struct PacketParser<'a> {
s: std::str::Chars<'a>,
}
impl PacketParser<'_> {
fn new(s: &str) -> PacketParser {
PacketParser { s: s.chars() }
}
fn take_string(&mut self, n: usize) -> String {
(&mut self.s).take(n).collect()
}
fn parse_number(&mut self, bits: usize) -> Result<u32, ParseIntError> {
u32::from_str_radix(&self.take_string(bits), 2)
}
fn parse_operator(&mut self, id: u32) -> PacketPayload {
let mut packets;
match self.parse_number(1).unwrap() {
0 => {
let len = self.parse_number(15).unwrap() as usize;
let substring = self.take_string(len);
let sub_parser = &mut PacketParser::new(&substring);
packets = Vec::new();
while let Ok(packet) = sub_parser.parse_packet() {
packets.push(packet);
}
}
1 => {
let n = self.parse_number(11).unwrap();
packets = Vec::with_capacity(n as usize);
for _ in 0..n {
packets.push(self.parse_packet().unwrap());
}
}
_ => unreachable!(),
}
PacketPayload::Operator(id, packets)
}
fn parse_literal(&mut self) -> PacketPayload {
let mut n = 0_u64;
loop {
let first_bit = self.s.next().unwrap();
n = (n << 1) + self.s.next().unwrap().to_digit(2).unwrap() as u64;
n = (n << 1) + self.s.next().unwrap().to_digit(2).unwrap() as u64;
n = (n << 1) + self.s.next().unwrap().to_digit(2).unwrap() as u64;
n = (n << 1) + self.s.next().unwrap().to_digit(2).unwrap() as u64;
if first_bit == '0' {
break;
}
}
PacketPayload::Literal(n)
}
fn parse_packet(&mut self) -> ParsePacketResult {
let version = self.parse_number(3)?;
let payload = match self.parse_number(3)? {
4 => self.parse_literal(),
id => self.parse_operator(id),
};
Ok(Packet { version, payload })
}
}
impl FromStr for Packet {
type Err = ParseIntError;
fn from_str(s: &str) -> ParsePacketResult {
let s = s
.chars()
.map(|c| c.to_digit(16).unwrap())
.map(|n| format!("{:04b}", n))
.collect::<String>();
let mut parser = PacketParser::new(&s);
parser.parse_packet()
}
}
fn sum_version_numbers(p: &Packet) -> u32 {
match &p.payload {
PacketPayload::Literal(_) => p.version as u32,
PacketPayload::Operator(_, subpackets) => {
p.version + subpackets.iter().map(sum_version_numbers).sum::<u32>()
}
}
}
fn eval_packet(p: &Packet) -> u64 {
match &p.payload {
PacketPayload::Literal(n) => *n as u64,
PacketPayload::Operator(id, subpackets) => match id {
0 => subpackets.iter().map(eval_packet).sum::<u64>(),
1 => subpackets.iter().map(eval_packet).product::<u64>(),
2 => subpackets.iter().map(eval_packet).min().unwrap(),
3 => subpackets.iter().map(eval_packet).max().unwrap(),
5 => {
assert_eq!(subpackets.len(), 2);
if eval_packet(&subpackets[0]) > eval_packet(&subpackets[1]) {
1
} else {
0
}
}
6 => {
assert_eq!(subpackets.len(), 2);
if eval_packet(&subpackets[0]) < eval_packet(&subpackets[1]) {
1
} else {
0
}
}
7 => {
assert_eq!(subpackets.len(), 2);
if eval_packet(&subpackets[0]) == eval_packet(&subpackets[1]) {
1
} else {
0
}
}
_ => panic!("invalid operator ID {}", id),
},
}
}
fn main() -> Result<(), ParseIntError> {
let input = include_str!("../inputs/day16.txt").trim_end();
let packet: Packet = input.parse()?;
println!("solution {}", sum_version_numbers(&packet));
println!("solution {}", eval_packet(&packet));
Ok(())
}
#[test]
fn test_literal() {
let packet: Packet = "D2FE28".parse().unwrap();
assert_eq!(
packet,
Packet {
version: 6,
payload: PacketPayload::Literal(2021)
}
);
}
#[test]
fn test_parse_type_0_operator() {
let packet: Packet = "38006F45291200".parse().unwrap();
let packets = vec![
Packet {
version: 6,
payload: PacketPayload::Literal(10),
},
Packet {
version: 2,
payload: PacketPayload::Literal(20),
},
];
assert_eq!(
packet,
Packet {
version: 1,
payload: PacketPayload::Operator(6, packets)
}
);
}
#[test]
fn test_parse_type_1_operator() {
let packet: Packet = "EE00D40C823060".parse().unwrap();
assert_eq!(
packet,
Packet {
version: 7,
payload: PacketPayload::Operator(
3,
vec![
Packet {
version: 2,
payload: PacketPayload::Literal(1)
},
Packet {
version: 4,
payload: PacketPayload::Literal(2)
},
Packet {
version: 1,
payload: PacketPayload::Literal(3)
},
]
)
}
);
}
#[test]
fn test_sum_version_numbers() {
let transmissions = [
"8A004A801A8002F478",
"620080001611562C8802118E34",
"C0015000016115A2E0802F182340",
"A0016C880162017C3686B18A3D4780",
];
let mut iter = transmissions
.iter()
.map(|t| sum_version_numbers(&t.parse().unwrap()));
assert_eq!(iter.next(), Some(16));
assert_eq!(iter.next(), Some(12));
assert_eq!(iter.next(), Some(23));
assert_eq!(iter.next(), Some(31));
}
#[test]
fn test_sum_operator() {
let packet: Packet = "C200B40A82".parse().unwrap();
assert_eq!(eval_packet(&packet), 3);
}
#[test]
fn test_product_operator() {
let packet: Packet = "04005AC33890".parse().unwrap();
assert_eq!(eval_packet(&packet), 54);
}
#[test]
fn test_minimum_operator() {
let packet: Packet = "880086C3E88112".parse().unwrap();
assert_eq!(eval_packet(&packet), 7);
}
#[test]
fn test_maximum_operator() {
let packet: Packet = "CE00C43D881120".parse().unwrap();
assert_eq!(eval_packet(&packet), 9);
}
#[test]
fn test_less_than_operator() {
let packet: Packet = "D8005AC2A8F0".parse().unwrap();
assert_eq!(eval_packet(&packet), 1);
}
#[test]
fn test_greater_than_operator() {
let packet: Packet = "F600BC2D8F".parse().unwrap();
assert_eq!(eval_packet(&packet), 0);
}
#[test]
fn test_equal_operator() {
let packet: Packet = "9C005AC2F8F0".parse().unwrap();
assert_eq!(eval_packet(&packet), 0);
}
#[test]
fn test_nested_equal_operator() {
let packet: Packet = "9C0141080250320F1802104A08".parse().unwrap();
assert_eq!(eval_packet(&packet), 1);
}

111
src/day17.rs Normal file
View File

@ -0,0 +1,111 @@
use std::ops::RangeInclusive;
#[derive(Clone, Debug)]
struct Area {
x: RangeInclusive<i32>,
y: RangeInclusive<i32>,
}
impl Area {
fn contains(&self, x: i32, y: i32) -> bool {
self.x.contains(&x) && self.y.contains(&y)
}
}
fn simulate(area: &Area, dx: i32, dy: i32) -> Option<i32> {
let mut hit = false;
let mut max_y = 0;
for step in 0..1000 {
let x = if step < dx {
// General solution for $ x_{t+1} - x_t = -t - dx + 1 $.
((2 * dx + 1) * step - step * step) / 2
} else {
// Special case when $ x_{t+1} - x_t = 0 $ is reached.
(dx * dx + dx) / 2
};
let y = ((2 * dy + 1) * step - step * step) / 2;
if y > max_y {
max_y = y;
}
if area.contains(x, y) {
hit = true;
}
if y < *area.y.start() {
break;
}
}
hit.then(|| max_y)
}
fn find_max_y(area: Area) -> i32 {
let mut max_y = 0;
for dx in 1..=*area.x.end() {
for dy in 1..1000 {
if let Some(y) = simulate(&area, dx, dy) {
if y > max_y {
max_y = y;
}
}
}
}
max_y
}
fn count_hits(area: Area) -> i32 {
let mut counter = 0;
for dx in 1..=*area.x.end() {
for dy in *area.y.start()..1000 {
if simulate(&area, dx, dy).is_some() {
counter += 1;
}
}
}
counter
}
fn main() {
let area = Area {
x: (179..=201),
y: (-109..=-63),
};
println!("solution {}", find_max_y(area.clone()));
println!("solution {}", count_hits(area));
}
#[test]
fn test_find_max_y() {
assert_eq!(
find_max_y(Area {
x: (20..=30),
y: (-10..=-5)
}),
45
);
}
#[test]
fn test_simulate() {
let area = Area {
x: (20..=30),
y: (-10..=-5),
};
assert_eq!(simulate(&area, 7, 2), Some(3));
assert_eq!(simulate(&area, 6, 3), Some(6));
assert_eq!(simulate(&area, 17, -4), None);
assert_eq!(simulate(&area, 6, 9), Some(45));
}
#[test]
fn test_count_hits() {
assert_eq!(
count_hits(Area {
x: (20..=30),
y: (-10..=-5)
}),
112
);
}

242
src/day18.rs Normal file
View File

@ -0,0 +1,242 @@
use std::fmt;
use std::ops::Add;
use std::str::FromStr;
#[derive(Clone)]
enum Value {
Number(u32, usize),
Pair(Box<Value>, Box<Value>),
}
impl Value {
fn new_pair(left: Value, right: Value) -> Self {
Value::Pair(Box::new(left), Box::new(right))
}
}
impl Value {
fn is_number_pair(&self) -> bool {
match self {
Value::Pair(left, right) => left.is_number() && right.is_number(),
Value::Number(_, _) => false,
}
}
fn is_number(&self) -> bool {
matches!(*self, Value::Number(_, _))
}
fn number(&self) -> Option<u32> {
match self {
Self::Number(n, _) => Some(*n),
_ => None,
}
}
fn index(&self) -> Option<usize> {
match self {
Self::Number(_, i) => Some(*i),
_ => None,
}
}
fn add_number(&mut self, n: u32) {
if let Self::Number(m, i) = self {
*self = Value::Number(*m + n, *i);
}
}
}
impl Add for Value {
type Output = Self;
fn add(self, other: Self) -> Self {
let mut v = Value::new_pair(self, other);
reduce(&mut v);
v
}
}
fn parse_pair(iter: &mut std::iter::Peekable<std::str::Chars>) -> Value {
if iter.next().unwrap() != '[' {
panic!();
}
let left = match iter.peek().unwrap() {
'[' => parse_pair(iter),
'0'..='9' => Value::Number(iter.next().unwrap().to_digit(10).unwrap(), 0),
_ => panic!(),
};
if iter.next().unwrap() != ',' {
panic!();
}
let right = match iter.peek().unwrap() {
'[' => parse_pair(iter),
'0'..='9' => Value::Number(iter.next().unwrap().to_digit(10).unwrap(), 0),
_ => panic!(),
};
if iter.next().unwrap() != ']' {
panic!();
}
Value::new_pair(left, right)
}
impl FromStr for Value {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut v = parse_pair(&mut s.chars().peekable());
renumber(&mut v);
Ok(v)
}
}
impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Value::Number(n, _) => write!(f, "{}", n),
Value::Pair(left, right) => write!(f, "[{},{}]", left, right),
}
}
}
fn find_exploded(tree: &Value, depth: usize) -> Option<&Value> {
if let Value::Pair(left, right) = tree {
if depth == 4 && tree.is_number_pair() {
Some(tree)
} else {
find_exploded(left, depth + 1).or_else(|| find_exploded(right, depth + 1))
}
} else {
None
}
}
fn find_number(tree: &mut Value, index: usize, n: u32) -> Option<&Value> {
match tree {
Value::Pair(left, right) => {
find_number(left, index, n).or_else(|| find_number(right, index, n))
}
Value::Number(_, i) if *i == index => {
tree.add_number(n);
Some(tree)
}
_ => None,
}
}
fn zero_pair(tree: &mut Value, index: usize) {
if let Value::Pair(left, right) = tree {
if let Value::Pair(ref n, _) = **left {
if let Value::Number(_, i) = **n {
if i == index {
*left = Box::new(Value::Number(0, 0));
return;
}
}
}
if let Value::Pair(ref n, _) = **right {
if let Value::Number(_, i) = **n {
if i == index {
*right = Box::new(Value::Number(0, 0));
return;
}
}
}
zero_pair(left, index);
zero_pair(right, index);
}
}
fn renumber_pair(value: &mut Value, counter: &mut usize) {
if let Value::Pair(left, right) = value {
renumber_pair(left.as_mut(), counter);
renumber_pair(right.as_mut(), counter);
}
if let Value::Number(n, _) = value {
*value = Value::Number(*n, *counter);
*counter += 1;
}
}
fn renumber(tree: &mut Value) {
let mut counter = 0;
renumber_pair(tree, &mut counter);
}
fn explode(tree: &mut Value) {
let exploded = &mut find_exploded(tree, 0);
if let Some(value) = exploded {
if let Value::Pair(left, right) = value {
let index = left.index().unwrap();
let left_n = left.number().unwrap();
let right_n = right.number().unwrap();
zero_pair(tree, index);
if index > 0 {
find_number(tree, index - 1, left_n);
}
find_number(tree, index + 2, right_n);
renumber(tree);
} else {
panic!();
}
}
}
fn reduce(value: &mut Value) -> &Value {
explode(value);
value
}
fn magnitude(value: Value) -> u64 {
match value {
Value::Number(n, _) => n as u64,
Value::Pair(left, right) => 3 * magnitude(*left) + 2 * magnitude(*right),
}
}
fn main() {
const INPUT: &str = include_str!("../inputs/day18.txt");
let reduced = INPUT
.lines()
.map(|line| line.parse().unwrap())
.reduce(|u: Value, v| u + v)
.unwrap();
println!("solution {}", magnitude(reduced));
}
#[test]
fn test_explode_left() {
let mut v: Value = "[[[[[9,8],1],2],3],4]".parse().unwrap();
assert_eq!(format!("{}", reduce(&mut v)), "[[[[0,9],2],3],4]");
}
#[test]
fn test_explode_right() {
let mut v: Value = "[7,[6,[5,[4,[3,2]]]]]".parse().unwrap();
assert_eq!(format!("{}", reduce(&mut v)), "[7,[6,[5,[7,0]]]]");
}
#[test]
fn test_explode_left_again() {
let mut v: Value = "[[6,[5,[4,[3,2]]]],1]".parse().unwrap();
assert_eq!(format!("{}", reduce(&mut v)), "[[6,[5,[7,0]]],3]");
}
#[test]
fn test_explode() {
let mut v: Value = "[[3,[2,[1,[7,3]]]],[6,[5,[4,[3,2]]]]]".parse().unwrap();
assert_eq!(
format!("{}", reduce(&mut v)),
"[[3,[2,[8,0]]],[9,[5,[4,[3,2]]]]]"
);
}
#[test]
fn test_magnitude() {
let v: Value = "[[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]"
.parse()
.unwrap();
assert_eq!(magnitude(v), 3488);
}

32
src/day19.rs Normal file
View File

@ -0,0 +1,32 @@
use std::collections::HashSet;
use std::str::FromStr;
struct Report(i32, i32, i32);
impl FromStr for Report {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut iter = s.splitn(3, ',').map(|n| n.parse().unwrap());
let x = iter.next().unwrap();
let y = iter.next().unwrap();
let z = iter.next().unwrap();
Ok(Self(x, y, z))
}
}
fn make_diffs(reports: &Vec<Report>) -> HashSet<Report> {
let mut set = HashSet::new();
for (i, report) in reports.iter().enumerate() {}
set
}
fn main() {
const INPUT: &str = include_str!("../inputs/day19.txt");
let reports = INPUT
.split("\n\n")
.map(|scanner| scanner.lines().map(|line| line.parse().unwrap()).collect())
.collect::<Vec<Vec<Report>>>();
let diffs: Vec<HashSet<Report>> = reports.iter().map(make_diffs).collect();
println!("solution {}", diffs.len());
}

158
src/day20.rs Normal file
View File

@ -0,0 +1,158 @@
use std::fmt;
use std::str::FromStr;
#[derive(Clone)]
struct Image {
image: Vec<Vec<char>>,
algorithm: Vec<char>,
background: bool,
}
impl Image {
fn is_light(&self, x: i32, y: i32) -> bool {
if x < 1 || y < 1 || x as usize > self.image[0].len() || y as usize > self.image.len() {
return self.background;
}
match self.image[(y - 1) as usize][(x - 1) as usize] {
'#' => true,
'.' => false,
p => panic!("invalid pixel '{}'", p),
}
}
fn enhance(self) -> Self {
let image = (0..self.image.len() + 2)
.map(|y| {
(0..self.image[0].len() + 2)
.map(|x| {
let mut idx = 0;
if self.is_light(x as i32 - 1, y as i32 - 1) {
idx += 0x100;
}
if self.is_light(x as i32, y as i32 - 1) {
idx += 0x080;
}
if self.is_light(x as i32 + 1, y as i32 - 1) {
idx += 0x040;
}
if self.is_light(x as i32 - 1, y as i32) {
idx += 0x020;
}
if self.is_light(x as i32, y as i32) {
idx += 0x010;
}
if self.is_light(x as i32 + 1, y as i32) {
idx += 0x008;
}
if self.is_light(x as i32 - 1, y as i32 + 1) {
idx += 0x004;
}
if self.is_light(x as i32, y as i32 + 1) {
idx += 0x002;
}
if self.is_light(x as i32 + 1, y as i32 + 1) {
idx += 0x001;
}
self.algorithm[idx]
})
.collect()
})
.collect();
let background = if self.algorithm[0] == '#' {
!self.background
} else {
false
};
Image {
image,
algorithm: self.algorithm,
background,
}
}
fn light_pixels(self) -> usize {
let result = self.enhance().enhance();
result
.image
.iter()
.map(|row| row.iter().filter(|p| **p == '#').count())
.sum()
}
fn super_light_pixels(self) -> usize {
let mut image = self;
for _ in 0..50 {
image = image.enhance();
}
image
.image
.iter()
.map(|row| row.iter().filter(|p| **p == '#').count())
.sum()
}
}
impl FromStr for Image {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (algorithm, image) = s.split_once("\n\n").unwrap();
let algorithm = algorithm.chars().collect();
let image = image
.lines()
.map(|line| line.trim_end().chars().collect())
.collect();
Ok(Image {
image,
algorithm,
background: false,
})
}
}
impl fmt::Debug for Image {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(
f,
"algorithm: {}\n",
self.algorithm.iter().collect::<String>()
)?;
for row in self.image.iter() {
writeln!(f, "{}", row.iter().collect::<String>())?;
}
Ok(())
}
}
fn main() {
const INPUT: &str = include_str!("../inputs/day20.txt");
let image: Image = INPUT.parse().unwrap();
println!("solution {}", image.clone().light_pixels());
println!("solution {}", image.super_light_pixels());
}
#[test]
fn test_light_pixels() {
const INPUT: &str = "..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..#
#..#.
#....
##..#
..#..
..###";
let image: Image = INPUT.parse().unwrap();
assert_eq!(image.light_pixels(), 35);
}
#[test]
fn test_super_light_pixels() {
const INPUT: &str = "..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..#
#..#.
#....
##..#
..#..
..###";
let image: Image = INPUT.parse().unwrap();
assert_eq!(image.super_light_pixels(), 3351);
}

122
src/day21.rs Normal file
View File

@ -0,0 +1,122 @@
use std::collections::HashMap;
struct DeterministicDice {
rolls: usize,
last: usize,
}
impl DeterministicDice {
fn new() -> DeterministicDice {
DeterministicDice { rolls: 0, last: 0 }
}
}
impl Iterator for DeterministicDice {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> {
self.rolls += 3;
let x = self.last % 100 + 1;
let y = (self.last + 1) % 100 + 1;
let z = (self.last + 2) % 100 + 1;
self.last = z;
Some(x + y + z)
}
}
fn turns_to_win(positions: (usize, usize)) -> (usize, usize) {
let mut dice = DeterministicDice::new();
let mut positions = positions;
let mut scores = (0, 0);
loop {
positions.0 = (positions.0 + dice.next().unwrap() - 1) % 10 + 1;
scores.0 += positions.0;
if scores.0 >= 1000 {
return (dice.rolls, scores.1);
}
positions.1 = (positions.1 + dice.next().unwrap() - 1) % 10 + 1;
scores.1 += positions.1;
if scores.1 >= 1000 {
return (dice.rolls, scores.0);
}
}
}
fn simulate_universes(positions: (usize, usize)) -> usize {
type GameState = ((usize, usize), (usize, usize));
let mut games: HashMap<GameState, usize> = HashMap::new();
let mut wins = (0, 0);
games.insert(((positions.0 - 1, positions.1 - 1), (0, 0)), 1);
let dice_rolls = [
3, 4, 5, 4, 5, 6, 5, 6, 7, 4, 5, 6, 5, 6, 7, 6, 7, 8, 5, 6, 7, 6, 7, 8, 7, 8, 9,
];
loop {
if games.is_empty() {
break;
}
let mut next_turn = HashMap::new();
for ((positions, scores), count) in games {
for player1_dice in dice_rolls {
let player1_position = (positions.0 + player1_dice) % 10;
let player1_score = scores.0 + player1_position + 1;
if player1_score < 21 {
for player2_dice in dice_rolls {
let player2_position = (positions.1 + player2_dice) % 10;
let player2_score = scores.1 + player2_position + 1;
if player2_score < 21 {
let new_count = next_turn
.entry((
(player1_position, player2_position),
(player1_score, player2_score),
))
.or_insert(0);
*new_count += count;
} else {
wins.1 += count;
}
}
} else {
wins.0 += count;
}
}
}
games = next_turn;
}
if wins.0 > wins.1 {
wins.0
} else {
wins.1
}
}
fn main() {
const INPUT: &str = include_str!("../inputs/day21.txt");
let positions = INPUT
.lines()
.map(|line| line.rsplit_once(' ').unwrap().1.parse().unwrap())
.collect::<Vec<usize>>();
let (turns, losing_score) = turns_to_win((positions[0], positions[1]));
println!("solution: {}", turns * losing_score);
println!(
"solution: {}",
simulate_universes((positions[0], positions[1]))
);
}
#[test]
fn test_turns_to_win() {
let (turns, losing_score) = turns_to_win((4, 8));
assert_eq!(turns, 993);
assert_eq!(losing_score, 745);
}
#[test]
fn test_simulate_universes() {
assert_eq!(simulate_universes((4, 8)), 444356092776315);
}

198
src/day22.rs Normal file
View File

@ -0,0 +1,198 @@
use std::{ops::RangeInclusive, str::FromStr};
#[derive(Clone, Debug)]
struct Cuboid {
positive: bool,
x: RangeInclusive<i64>,
y: RangeInclusive<i64>,
z: RangeInclusive<i64>,
}
fn contains_range(a: &RangeInclusive<i64>, b: &RangeInclusive<i64>) -> bool {
b.start() >= a.start() && b.end() <= a.end()
}
impl Cuboid {
fn contains(&self, other: &Cuboid) -> bool {
contains_range(&self.x, &other.x)
&& contains_range(&self.y, &other.y)
&& contains_range(&self.z, &other.z)
}
fn volume(&self) -> u64 {
((self.x.end() + 1 - self.x.start())
* (self.y.end() + 1 - self.y.start())
* (self.z.end() + 1 - self.z.start())) as u64
}
}
impl FromStr for Cuboid {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let positive = match &s[0..3] {
"on " => true,
"off" => false,
_ => return Err(()),
};
let w = s.splitn(12, &['=', '.', ','][..]).collect::<Vec<&str>>();
let x = w[1].parse().unwrap()..=w[3].parse().unwrap();
let y = w[5].parse().unwrap()..=w[7].parse().unwrap();
let z = w[9].parse().unwrap()..=w[11].parse().unwrap();
Ok(Cuboid { positive, x, y, z })
}
}
#[derive(Debug)]
struct Segments {
inner: Vec<RangeInclusive<i64>>,
}
impl Segments {
fn new(ranges: &[RangeInclusive<i64>]) -> Segments {
let mut starts = ranges.iter().map(|r| *r.start()).collect::<Vec<i64>>();
starts.sort_unstable();
starts.dedup();
let mut starts_iter = starts.into_iter().peekable();
let mut ends = ranges.iter().map(|r| *r.end()).collect::<Vec<i64>>();
ends.sort_unstable();
ends.dedup();
let mut ends_iter = ends.into_iter().peekable();
let mut inner = Vec::new();
let mut start = starts_iter.next().unwrap();
while let Some(maybe_end) = ends_iter.peek() {
if maybe_end < &start {
ends_iter.next();
continue;
}
if let Some(maybe_start) = starts_iter.peek() {
if maybe_start <= &start {
starts_iter.next();
continue;
}
if maybe_start <= maybe_end {
let end = starts_iter.next().unwrap();
inner.push(start..=end - 1);
start = end;
} else {
let end = ends_iter.next().unwrap();
inner.push(start..=end);
start = end + 1;
}
} else {
let end = ends_iter.next().unwrap();
inner.push(start..=end);
start = end + 1;
}
}
Segments { inner }
}
}
fn reboot(steps: &[Cuboid]) -> u64 {
let x_segments = Segments::new(
&steps
.iter()
.map(|s| s.x.clone())
.collect::<Vec<RangeInclusive<i64>>>(),
);
let y_segments = Segments::new(
&steps
.iter()
.map(|s| s.y.clone())
.collect::<Vec<RangeInclusive<i64>>>(),
);
let z_segments = Segments::new(
&steps
.iter()
.map(|s| s.z.clone())
.collect::<Vec<RangeInclusive<i64>>>(),
);
let mut count = 0;
for x in x_segments.inner {
let mut cuboid = Cuboid {
positive: true,
x: x.clone(),
y: 0..=0,
z: 0..=0,
};
for y in &y_segments.inner {
cuboid.y.clone_from(y);
for z in &z_segments.inner {
cuboid.z.clone_from(z);
let mut on = false;
for step in steps.iter() {
if step.contains(&cuboid) {
on = step.positive;
}
}
if on {
count += cuboid.volume()
}
}
}
}
count
}
fn main() {
const INPUT: &str = include_str!("../inputs/day22.txt");
let steps = INPUT
.lines()
.map(|line| line.parse().unwrap())
.collect::<Vec<Cuboid>>();
println!("solution {}", reboot(&steps[..20]));
println!("solution {}", reboot(&steps));
}
#[test]
fn test_example() {
const INPUT: &str = "on x=10..12,y=10..12,z=10..12
on x=11..13,y=11..13,z=11..13
off x=9..11,y=9..11,z=9..11
on x=10..10,y=10..10,z=10..10";
let steps = INPUT
.lines()
.map(|line| line.parse().unwrap())
.collect::<Vec<Cuboid>>();
assert_eq!(reboot(&steps), 39);
}
#[test]
fn test_reboot() {
const INPUT: &str = "on x=-20..26,y=-36..17,z=-47..7
on x=-20..33,y=-21..23,z=-26..28
on x=-22..28,y=-29..23,z=-38..16
on x=-46..7,y=-6..46,z=-50..-1
on x=-49..1,y=-3..46,z=-24..28
on x=2..47,y=-22..22,z=-23..27
on x=-27..23,y=-28..26,z=-21..29
on x=-39..5,y=-6..47,z=-3..44
on x=-30..21,y=-8..43,z=-13..34
on x=-22..26,y=-27..20,z=-29..19
off x=-48..-32,y=26..41,z=-47..-37
on x=-12..35,y=6..50,z=-50..-2
off x=-48..-32,y=-32..-16,z=-15..-5
on x=-18..26,y=-33..15,z=-7..46
off x=-40..-22,y=-38..-28,z=23..41
on x=-16..35,y=-41..10,z=-47..6
off x=-32..-23,y=11..30,z=-14..3
on x=-49..-5,y=-3..45,z=-29..18
off x=18..30,y=-20..-8,z=-3..13
on x=-41..9,y=-7..43,z=-33..15
";
let steps = INPUT
.lines()
.map(|line| line.parse().unwrap())
.collect::<Vec<Cuboid>>();
assert_eq!(reboot(&steps), 590784);
}

245
src/day23.rs Normal file
View File

@ -0,0 +1,245 @@
use std::cmp::Ordering;
use std::collections::{BinaryHeap, HashMap};
use std::fmt;
use std::hash::{Hash, Hasher};
#[derive(Copy, Clone, Eq)]
enum Space {
Empty = 1,
Amber,
Bronze,
Copper,
Desert,
}
impl Space {
fn cost(&self) -> usize {
match self {
Self::Amber => 1,
Self::Bronze => 10,
Self::Copper => 100,
Self::Desert => 1000,
_ => panic!("empty spaces don't move"),
}
}
fn glyph(&self) -> char {
match self {
Self::Empty => '.',
Self::Amber => 'A',
Self::Bronze => 'B',
Self::Copper => 'C',
Self::Desert => 'D',
}
}
}
impl Hash for Space {
fn hash<H: Hasher>(&self, state: &mut H) {
(*self as u32).hash(state);
}
}
impl PartialEq for Space {
fn eq(&self, other: &Self) -> bool {
*self as u32 == *other as u32
}
}
impl Ord for Space {
fn cmp(&self, other: &Self) -> Ordering {
(*other as u32).cmp(&(*self as u32))
}
}
impl PartialOrd for Space {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl fmt::Debug for Space {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.glyph())
}
}
#[derive(Copy, Clone, Eq, PartialEq)]
struct Step {
cost: usize,
position: [Space; 19],
}
impl Ord for Step {
fn cmp(&self, other: &Self) -> Ordering {
other
.cost
.cmp(&self.cost)
.then_with(|| self.position.cmp(&other.position))
}
}
impl PartialOrd for Step {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl fmt::Debug for Step {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "#############")?;
writeln!(
f,
"#{}#",
self.position[0..11]
.iter()
.map(|space| space.glyph())
.collect::<String>()
)?;
writeln!(
f,
"###{}#{}#{}#{}###",
self.position[11].glyph(),
self.position[13].glyph(),
self.position[15].glyph(),
self.position[17].glyph()
)?;
writeln!(
f,
" #{}#{}#{}#{}#",
self.position[12].glyph(),
self.position[14].glyph(),
self.position[16].glyph(),
self.position[18].glyph()
)?;
writeln!(f, " #########")
}
}
fn swap(position: [Space; 19], a: usize, b: usize) -> [Space; 19] {
let mut new_position = position;
new_position[a] = position[b];
new_position[b] = position[a];
new_position
}
struct Burrow {
goal: [Space; 19],
}
impl Burrow {
fn valid_moves(&self, position: [Space; 19]) -> Vec<([Space; 19], usize)> {
let mut moves = Vec::new();
for door in [2, 4, 6, 8] {
if position[door] != Space::Empty {
if position[door - 1] == Space::Empty {
moves.push((swap(position, door - 1, door), position[door].cost()));
}
if position[door + 1] == Space::Empty {
moves.push((swap(position, door, door + 1), position[door].cost()));
}
if !moves.is_empty() {
return moves;
}
}
}
for room in [11, 13, 15, 17] {
if position[room] != Space::Empty && position[room + 1] == Space::Empty {
moves.push((swap(position, room, room + 1), position[room].cost()));
}
if position[room + 1] != Space::Empty && position[room] == Space::Empty {
moves.push((swap(position, room, room + 1), position[room + 1].cost()));
}
if position[room] != Space::Empty && position[room - 9] == Space::Empty {
moves.push((swap(position, room, room - 9), position[room].cost()));
}
if (position[room - 9] != Space::Empty && position[room] == Space::Empty)
&& ((position[room - 9] == self.goal[room + 1]
&& position[room + 1] == Space::Empty)
|| (position[room - 9] == self.goal[room]
&& position[room + 1] == self.goal[room + 1]))
{
moves.push((swap(position, room - 9, room), position[room - 9].cost()));
}
}
for hallway in [1, 3, 5, 7, 9] {
if position[hallway] != Space::Empty {
if position[hallway - 1] == Space::Empty {
moves.push((
swap(position, hallway, hallway - 1),
position[hallway].cost(),
));
}
if position[hallway + 1] == Space::Empty {
moves.push((
swap(position, hallway, hallway + 1),
position[hallway].cost(),
));
}
}
}
if position[0] != Space::Empty && position[1] == Space::Empty {
moves.push((swap(position, 0, 1), position[0].cost()));
}
if position[10] != Space::Empty && position[9] == Space::Empty {
moves.push((swap(position, 9, 10), position[10].cost()));
}
moves
}
}
fn least_energy(start: &[Space; 19], goal: &[Space; 19]) -> Option<usize> {
let burrow = Burrow { goal: *goal };
let mut dist: HashMap<[Space; 19], usize> = HashMap::new();
let mut heap = BinaryHeap::new();
dist.insert(*start, 0);
heap.push(Step {
cost: 0,
position: *start,
});
while let Some(Step { cost, position }) = heap.pop() {
if &position == goal {
return Some(cost);
}
let d = dist.entry(position).or_insert(usize::MAX);
if &cost > d {
continue;
}
println!("{:?}", Step { cost, position });
let moves = burrow.valid_moves(position);
for (next_position, next_cost) in moves {
let next_cost = next_cost + cost;
let next = Step {
cost: next_cost,
position: next_position,
};
if &next_cost < dist.get(&next_position).unwrap_or(&usize::MAX) {
heap.push(next);
dist.insert(next_position, next_cost);
}
}
}
None
}
fn main() {
use Space::*;
let start = [
Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Amber, Amber,
Bronze, Bronze, Copper, Copper, Desert, Desert,
];
let goal = [
Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Desert,
Bronze, Desert, Amber, Copper, Amber, Bronze, Copper,
];
println!("solution {}", least_energy(&start, &goal).unwrap());
}

220
src/day24.rs Normal file
View File

@ -0,0 +1,220 @@
use std::str::FromStr;
#[derive(Copy, Clone)]
enum Operand {
W,
X,
Y,
Z,
Literal(i64),
}
impl FromStr for Operand {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"w" => Ok(Operand::W),
"x" => Ok(Operand::X),
"y" => Ok(Operand::Y),
"z" => Ok(Operand::Z),
_ => Ok(Operand::Literal(s.parse().unwrap())),
}
}
}
#[derive(Copy, Clone)]
enum Instruction {
Inp(Operand),
Add(Operand, Operand),
Mul(Operand, Operand),
Div(Operand, Operand),
Mod(Operand, Operand),
Eql(Operand, Operand),
}
impl FromStr for Instruction {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut iter = s.split_ascii_whitespace();
match iter.next().unwrap() {
"inp" => Ok(Instruction::Inp(iter.next().unwrap().parse().unwrap())),
"add" => Ok(Instruction::Add(
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
)),
"mul" => Ok(Instruction::Mul(
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
)),
"div" => Ok(Instruction::Div(
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
)),
"mod" => Ok(Instruction::Mod(
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
)),
"eql" => Ok(Instruction::Eql(
iter.next().unwrap().parse().unwrap(),
iter.next().unwrap().parse().unwrap(),
)),
_ => Err(()),
}
}
}
struct ArithmeticLogicUnit {
w: i64,
x: i64,
y: i64,
z: i64,
inputs: Vec<i64>,
}
impl ArithmeticLogicUnit {
fn new(inputs: &[i64]) -> ArithmeticLogicUnit {
ArithmeticLogicUnit {
w: 0,
x: 0,
y: 0,
z: 0,
inputs: inputs.to_vec(),
}
}
fn load(&self, register: Operand) -> i64 {
match register {
Operand::W => self.w,
Operand::X => self.x,
Operand::Y => self.y,
Operand::Z => self.z,
Operand::Literal(a) => a,
}
}
fn store(&mut self, register: Operand, value: i64) {
match register {
Operand::W => {
self.w = value;
}
Operand::X => {
self.x = value;
}
Operand::Y => {
self.y = value;
}
Operand::Z => {
self.z = value;
}
Operand::Literal(_) => panic!("can't store in literal"),
}
}
fn eval(&mut self, instruction: Instruction) {
match instruction {
Instruction::Inp(a) => {
let value = self.inputs.pop().unwrap();
self.store(a, value);
}
Instruction::Add(a, b) => {
let a_val = self.load(a);
let b = self.load(b);
self.store(a, a_val + b);
}
Instruction::Mul(a, b) => {
let a_val = self.load(a);
let b = self.load(b);
self.store(a, a_val * b);
}
Instruction::Div(a, b) => {
let a_val = self.load(a);
let b = self.load(b);
self.store(a, a_val / b);
}
Instruction::Mod(a, b) => {
let a_val = self.load(a);
let b = self.load(b);
self.store(a, a_val % b);
}
Instruction::Eql(a, b) => {
let a_val = self.load(a);
let b = self.load(b);
self.store(a, if a_val == b { 1 } else { 0 });
}
}
}
}
struct ModelNumber {
digits: [i64; 14],
}
impl ModelNumber {
fn new() -> ModelNumber {
ModelNumber { digits: [9; 14] }
}
}
impl Iterator for ModelNumber {
type Item = [i64; 14];
fn next(&mut self) -> Option<Self::Item> {
let mut i = 0;
loop {
self.digits[i] -= 1;
if self.digits[i] == 0 {
self.digits[i] = 9;
i += 1;
} else {
break;
}
}
Some(self.digits)
}
}
fn main() {
const INPUT: &str = include_str!("../inputs/day24.txt");
let instructions = INPUT
.lines()
.map(|line| line.parse().unwrap())
.collect::<Vec<Instruction>>();
let model_number = ModelNumber::new();
for digits in model_number {
let mut alu = ArithmeticLogicUnit::new(&digits);
for instruction in instructions.iter() {
alu.eval(*instruction);
}
if alu.z == 0 {
println!(
"solution {}",
digits
.iter()
.rev()
.map(|d| char::from_digit(*d as u32, 10).unwrap())
.collect::<String>()
);
break;
}
}
}
#[test]
fn test_negate() {
let mut alu = ArithmeticLogicUnit::new(&[42]);
alu.eval(Instruction::Inp(Operand::X));
alu.eval(Instruction::Mul(Operand::X, Operand::Literal(-1)));
assert_eq!(alu.x, -42);
}
#[test]
fn test_equals_triple() {
let mut alu = ArithmeticLogicUnit::new(&[12, 4]);
alu.eval(Instruction::Inp(Operand::Z));
alu.eval(Instruction::Inp(Operand::X));
alu.eval(Instruction::Mul(Operand::Z, Operand::Literal(3)));
alu.eval(Instruction::Eql(Operand::Z, Operand::X));
assert_eq!(alu.z, 1);
}

125
src/day25.rs Normal file
View File

@ -0,0 +1,125 @@
use std::fmt;
use std::str::FromStr;
#[derive(Copy, Clone, PartialEq)]
enum Herd {
East,
South,
}
struct SeaCucumberMap {
inner: Vec<Vec<Option<Herd>>>,
}
impl SeaCucumberMap {
fn stops_moving(&mut self) -> usize {
let mut steps = 0;
while self.step() {
steps += 1;
}
steps + 1
}
fn step(&mut self) -> bool {
let shifted: Vec<Vec<Option<Herd>>> =
(0..self.inner.len()).map(|i| self.shift_right(i)).collect();
let new_map = (0..self.inner.len())
.map(|i| self.shift_down(i, &shifted))
.collect();
let changed = self.inner != new_map;
self.inner = new_map;
changed
}
fn shift_right(&self, i: usize) -> Vec<Option<Herd>> {
let row = &self.inner[i];
let mut new_row = Vec::with_capacity(row.len());
for (i, loc) in row.iter().enumerate() {
let left = row[(i + row.len() - 1) % row.len()];
let right = row[(i + row.len() + 1) % row.len()];
new_row.push(match (left, loc, right) {
(Some(Herd::East), None, _) => left,
(_, Some(Herd::East), None) => None,
_ => *loc,
});
}
new_row
}
fn shift_down(&self, i: usize, shifted: &[Vec<Option<Herd>>]) -> Vec<Option<Herd>> {
let height = self.inner.len();
let row = &shifted[i];
let above_row = &shifted[(i + height - 1) % height];
let below_row = &shifted[(i + height + 1) % height];
let mut new_row = Vec::with_capacity(row.len());
for (above, (loc, below)) in above_row.iter().zip(row.iter().zip(below_row)) {
new_row.push(match (*above, *loc, below) {
(Some(Herd::South), None, _) => *above,
(_, Some(Herd::South), None) => None,
_ => *loc,
});
}
new_row
}
}
impl FromStr for SeaCucumberMap {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let inner = s
.lines()
.map(|line| {
line.chars()
.map(|c| match c {
'>' => Some(Herd::East),
'v' => Some(Herd::South),
'.' => None,
_ => panic!(),
})
.collect()
})
.collect();
Ok(SeaCucumberMap { inner })
}
}
impl fmt::Debug for SeaCucumberMap {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for row in self.inner.iter() {
writeln!(
f,
"{}",
row.iter()
.map(|c| match c {
Some(Herd::East) => '>',
Some(Herd::South) => 'v',
None => '.',
})
.collect::<String>()
)?;
}
Ok(())
}
}
fn main() {
const INPUT: &str = include_str!("../inputs/day25.txt");
let mut map: SeaCucumberMap = INPUT.parse().unwrap();
println!("solution {}", map.stops_moving());
}
#[test]
fn test_stops_moving() {
const INPUT: &str = "v...>>.vv>
.vv>>.vv..
>>.>v>...v
>>v>>.>.v.
v>v.vv.v..
>.>>..v...
.vv..>.>v.
v.v..>>v.v
....v..v.>";
let mut map: SeaCucumberMap = INPUT.parse().unwrap();
assert_eq!(map.stops_moving(), 58);
}