Compare commits
11 Commits
Author | SHA1 | Date |
---|---|---|
Ishan Jain | abf797fd6e | |
Ishan Jain | a2cafe726c | |
Ishan Jain | 56f8c5bc1f | |
Ishan Jain | f97789eac6 | |
Ishan Jain | 2f11a57ec2 | |
Ishan Jain | c58ea87895 | |
Ishan Jain | 3276d198ce | |
Ishan Jain | b1cef38c7a | |
Ishan Jain | 1e5d8585a9 | |
Ishan Jain | 8693ed5225 | |
Ishan Jain | 417abdc74a |
|
@ -5,3 +5,52 @@ version = 3
|
|||
[[package]]
|
||||
name = "aoc2021"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitvec",
|
||||
"hex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitvec"
|
||||
version = "0.22.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527"
|
||||
dependencies = [
|
||||
"funty",
|
||||
"radium",
|
||||
"tap",
|
||||
"wyz",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "funty"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "radium"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb"
|
||||
|
||||
[[package]]
|
||||
name = "tap"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||
|
||||
[[package]]
|
||||
name = "wyz"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188"
|
||||
dependencies = [
|
||||
"tap",
|
||||
]
|
||||
|
|
|
@ -6,6 +6,8 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bitvec = "0.22.3"
|
||||
hex = "0.4.3"
|
||||
|
||||
|
||||
[profile.release]
|
||||
|
|
911
inputs/input.txt
911
inputs/input.txt
|
@ -1,910 +1 @@
|
|||
724,201
|
||||
596,511
|
||||
883,560
|
||||
637,47
|
||||
869,537
|
||||
251,505
|
||||
851,618
|
||||
980,544
|
||||
818,661
|
||||
1093,390
|
||||
641,95
|
||||
1006,621
|
||||
447,434
|
||||
820,865
|
||||
475,847
|
||||
788,72
|
||||
1066,829
|
||||
1303,882
|
||||
1165,696
|
||||
164,229
|
||||
202,333
|
||||
244,485
|
||||
261,840
|
||||
1116,581
|
||||
976,513
|
||||
550,635
|
||||
1151,728
|
||||
1211,570
|
||||
228,422
|
||||
223,539
|
||||
406,369
|
||||
306,758
|
||||
1247,894
|
||||
760,859
|
||||
826,737
|
||||
340,637
|
||||
1293,47
|
||||
99,187
|
||||
264,553
|
||||
927,523
|
||||
940,189
|
||||
586,313
|
||||
525,67
|
||||
296,581
|
||||
353,694
|
||||
55,264
|
||||
582,491
|
||||
264,154
|
||||
512,394
|
||||
1101,225
|
||||
555,187
|
||||
1021,535
|
||||
805,772
|
||||
783,891
|
||||
403,402
|
||||
1243,94
|
||||
495,593
|
||||
1031,695
|
||||
13,472
|
||||
705,637
|
||||
459,618
|
||||
939,322
|
||||
251,82
|
||||
899,523
|
||||
301,131
|
||||
873,891
|
||||
880,374
|
||||
894,737
|
||||
306,593
|
||||
1257,280
|
||||
88,885
|
||||
621,655
|
||||
38,640
|
||||
514,539
|
||||
1222,885
|
||||
1257,135
|
||||
1191,303
|
||||
1034,715
|
||||
649,738
|
||||
719,103
|
||||
1131,367
|
||||
907,402
|
||||
169,297
|
||||
482,408
|
||||
977,866
|
||||
1280,432
|
||||
1087,803
|
||||
473,810
|
||||
182,546
|
||||
785,155
|
||||
1257,871
|
||||
1091,483
|
||||
310,52
|
||||
758,712
|
||||
870,715
|
||||
1211,772
|
||||
1173,40
|
||||
73,460
|
||||
117,312
|
||||
228,243
|
||||
918,822
|
||||
475,50
|
||||
765,3
|
||||
1113,410
|
||||
127,544
|
||||
880,422
|
||||
291,675
|
||||
1088,187
|
||||
957,506
|
||||
591,791
|
||||
566,437
|
||||
1178,593
|
||||
159,728
|
||||
1237,684
|
||||
490,665
|
||||
929,311
|
||||
641,267
|
||||
966,766
|
||||
1081,253
|
||||
735,649
|
||||
857,750
|
||||
999,367
|
||||
989,221
|
||||
0,185
|
||||
445,395
|
||||
108,168
|
||||
586,761
|
||||
1203,595
|
||||
1115,89
|
||||
838,665
|
||||
487,301
|
||||
289,647
|
||||
903,133
|
||||
251,53
|
||||
887,800
|
||||
1093,443
|
||||
775,684
|
||||
1026,481
|
||||
601,311
|
||||
661,476
|
||||
1198,627
|
||||
0,753
|
||||
1231,786
|
||||
410,821
|
||||
358,742
|
||||
1179,780
|
||||
763,435
|
||||
1077,133
|
||||
927,182
|
||||
681,144
|
||||
497,597
|
||||
1088,483
|
||||
649,476
|
||||
1202,415
|
||||
440,583
|
||||
1198,14
|
||||
104,775
|
||||
619,443
|
||||
410,660
|
||||
1034,656
|
||||
115,575
|
||||
601,728
|
||||
338,222
|
||||
84,301
|
||||
1111,891
|
||||
1211,122
|
||||
653,614
|
||||
1290,282
|
||||
209,582
|
||||
440,43
|
||||
929,583
|
||||
53,166
|
||||
1004,301
|
||||
263,572
|
||||
818,233
|
||||
1183,319
|
||||
228,472
|
||||
1257,166
|
||||
656,329
|
||||
53,135
|
||||
669,267
|
||||
815,593
|
||||
1111,767
|
||||
802,576
|
||||
1226,660
|
||||
1215,800
|
||||
341,218
|
||||
181,422
|
||||
1046,565
|
||||
159,280
|
||||
119,303
|
||||
1027,303
|
||||
147,417
|
||||
571,859
|
||||
1173,261
|
||||
1054,885
|
||||
239,302
|
||||
228,131
|
||||
85,217
|
||||
1231,226
|
||||
137,709
|
||||
21,131
|
||||
1290,612
|
||||
718,845
|
||||
837,782
|
||||
164,141
|
||||
632,467
|
||||
749,313
|
||||
525,379
|
||||
858,561
|
||||
851,786
|
||||
1228,857
|
||||
33,239
|
||||
868,670
|
||||
1183,3
|
||||
248,548
|
||||
328,345
|
||||
898,436
|
||||
438,893
|
||||
823,301
|
||||
820,589
|
||||
937,771
|
||||
875,58
|
||||
790,617
|
||||
64,504
|
||||
95,675
|
||||
508,576
|
||||
729,434
|
||||
186,91
|
||||
1092,392
|
||||
403,166
|
||||
87,514
|
||||
1261,114
|
||||
1141,597
|
||||
217,390
|
||||
689,151
|
||||
457,515
|
||||
585,805
|
||||
1131,360
|
||||
1212,472
|
||||
669,464
|
||||
318,682
|
||||
485,73
|
||||
1154,644
|
||||
738,37
|
||||
1297,870
|
||||
361,207
|
||||
932,238
|
||||
880,264
|
||||
376,738
|
||||
87,380
|
||||
174,94
|
||||
411,819
|
||||
845,633
|
||||
1288,721
|
||||
189,261
|
||||
1294,374
|
||||
72,267
|
||||
649,642
|
||||
156,644
|
||||
517,406
|
||||
705,562
|
||||
1059,614
|
||||
813,856
|
||||
623,702
|
||||
619,462
|
||||
403,728
|
||||
344,52
|
||||
1178,634
|
||||
1275,238
|
||||
656,47
|
||||
1176,169
|
||||
244,821
|
||||
328,121
|
||||
1092,255
|
||||
872,1
|
||||
845,185
|
||||
251,707
|
||||
79,674
|
||||
659,705
|
||||
1048,520
|
||||
1121,709
|
||||
107,768
|
||||
427,334
|
||||
1257,311
|
||||
112,14
|
||||
997,351
|
||||
552,429
|
||||
1064,159
|
||||
1114,453
|
||||
398,306
|
||||
1208,182
|
||||
187,175
|
||||
654,719
|
||||
1225,665
|
||||
735,245
|
||||
1078,245
|
||||
544,598
|
||||
691,238
|
||||
1168,164
|
||||
264,740
|
||||
855,833
|
||||
1260,267
|
||||
661,156
|
||||
333,194
|
||||
1212,870
|
||||
555,803
|
||||
445,11
|
||||
1275,443
|
||||
1067,35
|
||||
783,787
|
||||
785,379
|
||||
162,141
|
||||
661,866
|
||||
873,3
|
||||
321,476
|
||||
1136,800
|
||||
673,47
|
||||
723,800
|
||||
1129,84
|
||||
127,891
|
||||
927,371
|
||||
781,647
|
||||
1099,247
|
||||
1275,3
|
||||
691,891
|
||||
218,639
|
||||
731,626
|
||||
1093,504
|
||||
550,735
|
||||
1019,880
|
||||
477,142
|
||||
147,508
|
||||
392,822
|
||||
542,432
|
||||
209,235
|
||||
410,234
|
||||
895,113
|
||||
107,798
|
||||
7,23
|
||||
119,591
|
||||
709,364
|
||||
1059,340
|
||||
1198,148
|
||||
179,360
|
||||
226,49
|
||||
43,98
|
||||
195,640
|
||||
452,561
|
||||
49,52
|
||||
359,761
|
||||
1307,749
|
||||
1235,392
|
||||
556,355
|
||||
547,58
|
||||
790,725
|
||||
8,683
|
||||
1261,724
|
||||
301,185
|
||||
69,89
|
||||
545,339
|
||||
957,759
|
||||
509,84
|
||||
1235,564
|
||||
663,12
|
||||
1017,743
|
||||
739,332
|
||||
1213,392
|
||||
1067,444
|
||||
291,616
|
||||
969,851
|
||||
353,819
|
||||
669,95
|
||||
902,436
|
||||
127,575
|
||||
887,143
|
||||
671,79
|
||||
796,539
|
||||
865,11
|
||||
289,247
|
||||
465,709
|
||||
605,724
|
||||
194,581
|
||||
1223,788
|
||||
810,771
|
||||
932,208
|
||||
333,225
|
||||
1308,96
|
||||
1257,23
|
||||
709,311
|
||||
87,123
|
||||
845,807
|
||||
845,574
|
||||
552,630
|
||||
1226,234
|
||||
16,374
|
||||
1247,0
|
||||
381,311
|
||||
957,11
|
||||
393,392
|
||||
545,219
|
||||
523,332
|
||||
820,661
|
||||
472,229
|
||||
1079,542
|
||||
99,570
|
||||
311,847
|
||||
1130,500
|
||||
519,135
|
||||
207,434
|
||||
435,235
|
||||
373,499
|
||||
731,368
|
||||
800,348
|
||||
373,771
|
||||
904,861
|
||||
687,192
|
||||
1297,24
|
||||
681,131
|
||||
545,555
|
||||
705,170
|
||||
1009,200
|
||||
63,828
|
||||
1193,582
|
||||
211,647
|
||||
982,495
|
||||
1206,159
|
||||
1014,581
|
||||
284,481
|
||||
1294,394
|
||||
5,156
|
||||
641,627
|
||||
744,885
|
||||
900,212
|
||||
557,887
|
||||
908,289
|
||||
786,856
|
||||
785,515
|
||||
527,61
|
||||
73,684
|
||||
698,637
|
||||
522,294
|
||||
79,226
|
||||
843,175
|
||||
754,315
|
||||
798,606
|
||||
25,730
|
||||
790,169
|
||||
947,686
|
||||
509,646
|
||||
157,38
|
||||
994,451
|
||||
31,702
|
||||
622,453
|
||||
390,742
|
||||
256,558
|
||||
1274,448
|
||||
950,833
|
||||
619,238
|
||||
723,94
|
||||
67,94
|
||||
490,383
|
||||
447,658
|
||||
654,686
|
||||
407,313
|
||||
1054,9
|
||||
982,175
|
||||
1215,766
|
||||
1198,880
|
||||
1054,306
|
||||
1305,156
|
||||
407,245
|
||||
328,208
|
||||
273,787
|
||||
693,807
|
||||
939,751
|
||||
232,245
|
||||
1047,770
|
||||
1063,133
|
||||
87,828
|
||||
1285,409
|
||||
787,803
|
||||
1056,715
|
||||
654,701
|
||||
1201,56
|
||||
865,728
|
||||
1000,318
|
||||
546,31
|
||||
671,63
|
||||
490,29
|
||||
863,658
|
||||
234,841
|
||||
940,481
|
||||
7,460
|
||||
1213,495
|
||||
411,75
|
||||
1280,856
|
||||
949,599
|
||||
743,106
|
||||
301,435
|
||||
390,497
|
||||
416,157
|
||||
411,523
|
||||
1057,12
|
||||
907,492
|
||||
1138,486
|
||||
132,301
|
||||
383,571
|
||||
833,304
|
||||
271,323
|
||||
788,238
|
||||
726,112
|
||||
30,432
|
||||
1288,313
|
||||
688,441
|
||||
605,649
|
||||
982,345
|
||||
174,652
|
||||
527,721
|
||||
284,257
|
||||
927,571
|
||||
623,254
|
||||
1082,243
|
||||
977,669
|
||||
472,665
|
||||
705,724
|
||||
947,768
|
||||
559,800
|
||||
951,133
|
||||
207,460
|
||||
279,247
|
||||
360,833
|
||||
1223,514
|
||||
63,0
|
||||
182,5
|
||||
522,520
|
||||
17,495
|
||||
555,324
|
||||
390,397
|
||||
827,882
|
||||
107,683
|
||||
430,856
|
||||
1150,656
|
||||
579,788
|
||||
769,170
|
||||
164,677
|
||||
1082,651
|
||||
883,894
|
||||
982,656
|
||||
641,198
|
||||
576,320
|
||||
863,210
|
||||
857,144
|
||||
984,549
|
||||
672,766
|
||||
67,800
|
||||
35,443
|
||||
412,682
|
||||
326,529
|
||||
304,621
|
||||
556,539
|
||||
117,669
|
||||
918,72
|
||||
654,47
|
||||
219,388
|
||||
654,753
|
||||
1246,56
|
||||
654,641
|
||||
1250,848
|
||||
562,681
|
||||
72,403
|
||||
1228,305
|
||||
641,422
|
||||
758,856
|
||||
1082,472
|
||||
701,256
|
||||
1077,761
|
||||
820,511
|
||||
755,324
|
||||
658,509
|
||||
960,733
|
||||
801,10
|
||||
769,378
|
||||
430,38
|
||||
647,12
|
||||
129,291
|
||||
201,750
|
||||
522,374
|
||||
837,422
|
||||
75,564
|
||||
977,225
|
||||
609,256
|
||||
855,350
|
||||
1128,5
|
||||
1245,495
|
||||
1240,530
|
||||
591,551
|
||||
555,154
|
||||
45,275
|
||||
381,359
|
||||
922,253
|
||||
1026,257
|
||||
251,280
|
||||
629,798
|
||||
739,371
|
||||
492,708
|
||||
719,551
|
||||
508,318
|
||||
678,427
|
||||
1109,302
|
||||
754,539
|
||||
884,472
|
||||
705,245
|
||||
654,453
|
||||
256,530
|
||||
1184,793
|
||||
79,201
|
||||
731,788
|
||||
1076,53
|
||||
430,264
|
||||
999,54
|
||||
691,432
|
||||
837,810
|
||||
669,696
|
||||
181,810
|
||||
132,520
|
||||
885,641
|
||||
117,480
|
||||
729,460
|
||||
437,891
|
||||
242,212
|
||||
1263,507
|
||||
353,75
|
||||
316,787
|
||||
179,24
|
||||
967,815
|
||||
490,305
|
||||
214,583
|
||||
801,646
|
||||
1278,441
|
||||
1163,392
|
||||
485,521
|
||||
845,709
|
||||
104,159
|
||||
276,715
|
||||
85,229
|
||||
522,145
|
||||
214,851
|
||||
377,257
|
||||
490,661
|
||||
1285,485
|
||||
278,828
|
||||
492,661
|
||||
363,686
|
||||
709,82
|
||||
970,705
|
||||
535,882
|
||||
256,364
|
||||
131,114
|
||||
427,635
|
||||
440,179
|
||||
890,681
|
||||
1029,571
|
||||
360,61
|
||||
78,413
|
||||
746,179
|
||||
1128,889
|
||||
1288,173
|
||||
1213,47
|
||||
321,700
|
||||
137,40
|
||||
720,315
|
||||
1241,89
|
||||
137,807
|
||||
99,539
|
||||
104,287
|
||||
527,891
|
||||
415,116
|
||||
229,253
|
||||
574,605
|
||||
276,686
|
||||
329,838
|
||||
1309,728
|
||||
95,667
|
||||
899,819
|
||||
561,805
|
||||
669,430
|
||||
1206,735
|
||||
1006,313
|
||||
231,542
|
||||
438,669
|
||||
1211,355
|
||||
947,880
|
||||
783,168
|
||||
93,581
|
||||
415,302
|
||||
195,254
|
||||
231,784
|
||||
442,670
|
||||
872,225
|
||||
800,98
|
||||
817,58
|
||||
1079,94
|
||||
341,340
|
||||
131,780
|
||||
426,315
|
||||
1211,826
|
||||
1247,707
|
||||
363,219
|
||||
406,817
|
||||
820,383
|
||||
465,633
|
||||
547,459
|
||||
334,605
|
||||
1115,254
|
||||
927,164
|
||||
5,866
|
||||
239,778
|
||||
97,847
|
||||
271,730
|
||||
75,392
|
||||
438,225
|
||||
326,686
|
||||
570,301
|
||||
564,179
|
||||
195,192
|
||||
1225,217
|
||||
751,367
|
||||
477,116
|
||||
1116,805
|
||||
801,84
|
||||
247,674
|
||||
189,126
|
||||
1101,499
|
||||
1161,570
|
||||
989,418
|
||||
400,491
|
||||
810,123
|
||||
468,397
|
||||
1235,523
|
||||
803,607
|
||||
247,133
|
||||
0,847
|
||||
1146,305
|
||||
884,315
|
||||
164,569
|
||||
913,313
|
||||
412,212
|
||||
112,627
|
||||
209,312
|
||||
711,523
|
||||
427,894
|
||||
1235,140
|
||||
131,803
|
||||
1232,413
|
||||
199,891
|
||||
49,724
|
||||
947,14
|
||||
313,351
|
||||
898,10
|
||||
1277,655
|
||||
887,334
|
||||
982,719
|
||||
1230,829
|
||||
316,222
|
||||
209,728
|
||||
592,845
|
||||
1285,803
|
||||
490,589
|
||||
903,245
|
||||
283,591
|
||||
1197,516
|
||||
197,827
|
||||
619,451
|
||||
509,884
|
||||
1297,43
|
||||
1141,73
|
||||
1131,63
|
||||
584,530
|
||||
820,29
|
||||
107,836
|
||||
251,841
|
||||
529,247
|
||||
400,715
|
||||
607,387
|
||||
301,759
|
||||
1048,374
|
||||
227,707
|
||||
281,771
|
||||
711,607
|
||||
1049,392
|
||||
304,313
|
||||
1235,626
|
||||
209,883
|
||||
452,333
|
||||
30,408
|
||||
403,492
|
||||
510,98
|
||||
933,68
|
||||
161,58
|
||||
1242,693
|
||||
251,389
|
||||
1191,322
|
||||
1131,527
|
||||
1213,439
|
||||
586,201
|
||||
904,369
|
||||
783,319
|
||||
929,359
|
||||
838,348
|
||||
878,411
|
||||
109,443
|
||||
1082,131
|
||||
350,621
|
||||
1048,889
|
||||
326,208
|
||||
763,96
|
||||
132,593
|
||||
84,350
|
||||
1059,82
|
||||
678,467
|
||||
1091,836
|
||||
1235,371
|
||||
582,715
|
||||
641,464
|
||||
55,795
|
||||
293,687
|
||||
723,336
|
||||
341,472
|
||||
371,322
|
||||
555,602
|
||||
840,500
|
||||
199,833
|
||||
455,833
|
||||
169,73
|
||||
97,392
|
||||
783,385
|
||||
623,640
|
||||
1111,840
|
||||
765,891
|
||||
1046,553
|
||||
383,164
|
||||
907,812
|
||||
1131,870
|
||||
1067,892
|
||||
1129,472
|
||||
246,436
|
||||
644,670
|
||||
624,38
|
||||
353,135
|
||||
666,227
|
||||
835,399
|
||||
112,148
|
||||
247,859
|
||||
383,99
|
||||
535,684
|
||||
338,555
|
||||
552,805
|
||||
594,17
|
||||
880,472
|
||||
801,436
|
||||
997,472
|
||||
559,667
|
||||
341,676
|
||||
247,35
|
||||
1193,225
|
||||
1,56
|
||||
545,3
|
||||
1149,58
|
||||
455,710
|
||||
753,887
|
||||
687,640
|
||||
1220,379
|
||||
1115,724
|
||||
1203,574
|
||||
465,320
|
||||
84,772
|
||||
1273,359
|
||||
873,339
|
||||
783,3
|
||||
199,54
|
||||
1193,669
|
||||
264,329
|
||||
246,513
|
||||
33,655
|
||||
1293,495
|
||||
432,187
|
||||
601,871
|
||||
803,47
|
||||
825,373
|
||||
259,110
|
||||
586,245
|
||||
412,436
|
||||
927,347
|
||||
345,775
|
||||
970,257
|
||||
870,311
|
||||
|
||||
fold along x=655
|
||||
fold along y=447
|
||||
fold along x=327
|
||||
fold along y=223
|
||||
fold along x=163
|
||||
fold along y=111
|
||||
fold along x=81
|
||||
fold along y=55
|
||||
fold along x=40
|
||||
fold along y=27
|
||||
fold along y=13
|
||||
fold along y=6
|
||||
target area: x=124..174, y=-123..-86
|
||||
|
|
|
@ -1,21 +1 @@
|
|||
6,10
|
||||
0,14
|
||||
9,10
|
||||
0,3
|
||||
10,4
|
||||
4,11
|
||||
6,0
|
||||
6,12
|
||||
4,1
|
||||
0,13
|
||||
10,12
|
||||
3,4
|
||||
3,0
|
||||
8,4
|
||||
1,10
|
||||
2,14
|
||||
8,10
|
||||
9,0
|
||||
|
||||
fold along y=7
|
||||
fold along x=5
|
||||
target area: x=20..30, y=-10..-5
|
||||
|
|
162
src/main.rs
162
src/main.rs
|
@ -1,4 +1,6 @@
|
|||
#![feature(test)]
|
||||
|
||||
use std::ops::RangeInclusive;
|
||||
extern crate test;
|
||||
|
||||
const INPUTS: [&'static str; 2] = [
|
||||
|
@ -6,132 +8,78 @@ const INPUTS: [&'static str; 2] = [
|
|||
include_str!("../inputs/input.txt"),
|
||||
];
|
||||
|
||||
#[derive(Copy, Eq, PartialEq, Clone)]
|
||||
enum NodeType {
|
||||
Dot,
|
||||
Empty,
|
||||
fn parse(input: &'static str) -> (RangeInclusive<i32>, RangeInclusive<i32>) {
|
||||
let input = input.trim();
|
||||
let input = input.trim_start_matches("target area: ");
|
||||
|
||||
let (x, y) = input.split_once(", ").unwrap();
|
||||
|
||||
let x = x.trim_start_matches("x=");
|
||||
let y = y.trim_start_matches("y=");
|
||||
|
||||
let (sx, ex) = x
|
||||
.split_once("..")
|
||||
.map(|(a, b)| (a.parse::<i32>().unwrap(), b.parse::<i32>().unwrap()))
|
||||
.unwrap();
|
||||
let (sy, ey) = y
|
||||
.split_once("..")
|
||||
.map(|(a, b)| (a.parse::<i32>().unwrap(), b.parse::<i32>().unwrap()))
|
||||
.unwrap();
|
||||
|
||||
(sx..=ex, sy..=ey)
|
||||
}
|
||||
|
||||
impl NodeType {
|
||||
#[inline]
|
||||
const fn or(&self, rhs: &NodeType) -> NodeType {
|
||||
match (self, rhs) {
|
||||
(_, NodeType::Dot) | (NodeType::Dot, _) => NodeType::Dot,
|
||||
_ => NodeType::Empty,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn check(mut vx: i32, mut vy: i32, (tx, ty): (RangeInclusive<i32>, RangeInclusive<i32>)) -> bool {
|
||||
let mut sx = 0;
|
||||
let mut sy = 0;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct Point {
|
||||
x: usize,
|
||||
y: usize,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum Fold {
|
||||
X(usize),
|
||||
Y(usize),
|
||||
}
|
||||
|
||||
fn parse_input(input: &'static str) -> (Vec<Point>, Vec<Fold>) {
|
||||
let mut input = input.split("\n\n");
|
||||
|
||||
let points = input
|
||||
.next()
|
||||
.unwrap()
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let (x, y) = line.split_once(',').unwrap();
|
||||
|
||||
Point {
|
||||
x: usize::from_str_radix(x, 10).unwrap(),
|
||||
y: usize::from_str_radix(y, 10).unwrap(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let folds = input
|
||||
.next()
|
||||
.unwrap()
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let line = line.trim_start_matches("fold along ");
|
||||
let (axis, position) = line.split_once('=').unwrap();
|
||||
|
||||
let position = usize::from_str_radix(position, 10).unwrap();
|
||||
match axis {
|
||||
"x" => Fold::X(position),
|
||||
"y" => Fold::Y(position),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
(points, folds)
|
||||
}
|
||||
|
||||
fn solution((points, folds): (Vec<Point>, Vec<Fold>)) -> u64 {
|
||||
let mut y_max = 0;
|
||||
let mut x_max = 0;
|
||||
for point in points.iter() {
|
||||
y_max = std::cmp::max(y_max, point.y);
|
||||
x_max = std::cmp::max(x_max, point.x);
|
||||
}
|
||||
let mut grid = vec![vec![NodeType::Empty; x_max + 2]; y_max + 2];
|
||||
|
||||
for point in points {
|
||||
grid[point.y][point.x] = NodeType::Dot
|
||||
}
|
||||
|
||||
for fold in folds {
|
||||
let m = grid.len();
|
||||
let n = grid[0].len();
|
||||
match fold {
|
||||
Fold::X(position) => {
|
||||
for j in 0..m {
|
||||
for i in (0..position).rev() {
|
||||
let mirror = std::mem::replace(&mut grid[j][n - i - 1], NodeType::Empty);
|
||||
grid[j][i] = grid[j][i].or(&mirror);
|
||||
}
|
||||
}
|
||||
}
|
||||
Fold::Y(position) => {
|
||||
for i in 0..n {
|
||||
for j in (0..position).rev() {
|
||||
let mirror =
|
||||
std::mem::replace(&mut grid[2 * position - j][i], NodeType::Empty);
|
||||
grid[j][i] = grid[j][i].or(&mirror);
|
||||
}
|
||||
}
|
||||
}
|
||||
loop {
|
||||
if vx == 0 && sy < *ty.start() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut sum = 0;
|
||||
for row in grid {
|
||||
sum += row.into_iter().fold(0, |a, x| match x {
|
||||
NodeType::Dot => a + 1,
|
||||
NodeType::Empty => a,
|
||||
})
|
||||
if tx.contains(&sx) && ty.contains(&sy) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return sum;
|
||||
sx += vx;
|
||||
sy += vy;
|
||||
|
||||
vy -= 1;
|
||||
vx -= if vx > 0 {
|
||||
1
|
||||
} else if vx < 0 {
|
||||
-1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn solution((xr, yr): (RangeInclusive<i32>, RangeInclusive<i32>)) -> i32 {
|
||||
let mut count = 0;
|
||||
for x in 0..250 {
|
||||
for y in -250..=250 {
|
||||
if check(x, y, (xr.clone(), yr.clone())) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
0
|
||||
count
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for input in INPUTS {
|
||||
let input = parse_input(input);
|
||||
let input = parse(input);
|
||||
let result = solution(input);
|
||||
println!("Result {}", result);
|
||||
println!("Result = {}", result);
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn solution_bench(b: &mut test::Bencher) {
|
||||
let input = parse_input(INPUTS[1]);
|
||||
let input = parse(INPUTS[1]);
|
||||
b.iter(|| {
|
||||
let result = solution(input.clone());
|
||||
test::black_box(result);
|
||||
|
|
Loading…
Reference in New Issue