Added AOC 2020 day 16 - 20
This commit is contained in:
parent
e48d412783
commit
c016472838
63
www/statics/aoc/2020/16_challenge.txt
Normal file
63
www/statics/aoc/2020/16_challenge.txt
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
As you're walking to yet another connecting flight, you realize that one of the legs of your re-routed trip coming up is on a high-speed train. However, the train ticket you were given is in a language you don't understand. You should probably figure out what it says before you get to the train station after the next flight.
|
||||||
|
|
||||||
|
Unfortunately, you can't actually read the words on the ticket. You can, however, read the numbers, and so you figure out the fields these tickets must have and the valid ranges for values in those fields.
|
||||||
|
|
||||||
|
You collect the rules for ticket fields, the numbers on your ticket, and the numbers on other nearby tickets for the same train service (via the airport security cameras) together into a single document you can reference (your puzzle input).
|
||||||
|
|
||||||
|
The rules for ticket fields specify a list of fields that exist somewhere on the ticket and the valid ranges of values for each field. For example, a rule like class: 1-3 or 5-7 means that one of the fields in every ticket is named class and can be any value in the ranges 1-3 or 5-7 (inclusive, such that 3 and 5 are both valid in this field, but 4 is not).
|
||||||
|
|
||||||
|
Each ticket is represented by a single line of comma-separated values. The values are the numbers on the ticket in the order they appear; every ticket has the same format. For example, consider this ticket:
|
||||||
|
|
||||||
|
.--------------------------------------------------------.
|
||||||
|
| ????: 101 ?????: 102 ??????????: 103 ???: 104 |
|
||||||
|
| |
|
||||||
|
| ??: 301 ??: 302 ???????: 303 ??????? |
|
||||||
|
| ??: 401 ??: 402 ???? ????: 403 ????????? |
|
||||||
|
'--------------------------------------------------------'
|
||||||
|
|
||||||
|
Here, ? represents text in a language you don't understand. This ticket might be represented as 101,102,103,104,301,302,303,401,402,403; of course, the actual train tickets you're looking at are much more complicated. In any case, you've extracted just the numbers in such a way that the first number is always the same specific field, the second number is always a different specific field, and so on - you just don't know what each position actually means!
|
||||||
|
|
||||||
|
Start by determining which tickets are completely invalid; these are tickets that contain values which aren't valid for any field. Ignore your ticket for now.
|
||||||
|
|
||||||
|
For example, suppose you have the following notes:
|
||||||
|
|
||||||
|
class: 1-3 or 5-7
|
||||||
|
row: 6-11 or 33-44
|
||||||
|
seat: 13-40 or 45-50
|
||||||
|
|
||||||
|
your ticket:
|
||||||
|
7,1,14
|
||||||
|
|
||||||
|
nearby tickets:
|
||||||
|
7,3,47
|
||||||
|
40,4,50
|
||||||
|
55,2,20
|
||||||
|
38,6,12
|
||||||
|
|
||||||
|
It doesn't matter which position corresponds to which field; you can identify invalid nearby tickets by considering only whether tickets contain values that are not valid for any field. In this example, the values on the first nearby ticket are all valid for at least one field. This is not true of the other three nearby tickets: the values 4, 55, and 12 are are not valid for any field. Adding together all of the invalid values produces your ticket scanning error rate: 4 + 55 + 12 = 71.
|
||||||
|
|
||||||
|
Consider the validity of the nearby tickets you scanned. What is your ticket scanning error rate?
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Now that you've identified which tickets contain invalid values, discard those tickets entirely. Use the remaining valid tickets to determine which field is which.
|
||||||
|
|
||||||
|
Using the valid ranges for each field, determine what order the fields appear on the tickets. The order is consistent between all tickets: if seat is the third field, it is the third field on every ticket, including your ticket.
|
||||||
|
|
||||||
|
For example, suppose you have the following notes:
|
||||||
|
|
||||||
|
class: 0-1 or 4-19
|
||||||
|
row: 0-5 or 8-19
|
||||||
|
seat: 0-13 or 16-19
|
||||||
|
|
||||||
|
your ticket:
|
||||||
|
11,12,13
|
||||||
|
|
||||||
|
nearby tickets:
|
||||||
|
3,9,18
|
||||||
|
15,1,5
|
||||||
|
5,14,9
|
||||||
|
|
||||||
|
Based on the nearby tickets in the above example, the first position must be row, the second position must be class, and the third position must be seat; you can conclude that in your ticket, class is 12, row is 11, and seat is 13.
|
||||||
|
|
||||||
|
Once you work out which field is which, look for the six fields on your ticket that start with the word departure. What do you get if you multiply those six values together?
|
270
www/statics/aoc/2020/16_input.txt
Normal file
270
www/statics/aoc/2020/16_input.txt
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
departure location: 42-322 or 347-954
|
||||||
|
departure station: 49-533 or 555-966
|
||||||
|
departure platform: 28-86 or 101-974
|
||||||
|
departure track: 50-150 or 156-950
|
||||||
|
departure date: 30-117 or 129-957
|
||||||
|
departure time: 31-660 or 678-951
|
||||||
|
arrival location: 26-482 or 504-959
|
||||||
|
arrival station: 29-207 or 220-971
|
||||||
|
arrival platform: 28-805 or 829-964
|
||||||
|
arrival track: 48-377 or 401-964
|
||||||
|
class: 28-138 or 145-959
|
||||||
|
duration: 33-182 or 205-966
|
||||||
|
price: 25-437 or 449-962
|
||||||
|
route: 41-403 or 428-968
|
||||||
|
row: 33-867 or 880-960
|
||||||
|
seat: 40-921 or 930-955
|
||||||
|
train: 47-721 or 732-955
|
||||||
|
type: 33-243 or 265-964
|
||||||
|
wagon: 31-756 or 768-973
|
||||||
|
zone: 50-690 or 713-967
|
||||||
|
|
||||||
|
your ticket:
|
||||||
|
67,107,59,79,53,131,61,101,71,73,137,109,157,113,173,103,83,167,149,163
|
||||||
|
|
||||||
|
nearby tickets:
|
||||||
|
179,948,890,368,224,849,508,533,931,918,864,792,592,356,895,62,540,744,902,559
|
||||||
|
363,432,890,266,55,794,624,60,732,756,325,508,167,70,593,477,906,865,572,889
|
||||||
|
682,482,782,319,82,269,837,205,638,509,316,885,66,240,144,105,181,370,565,366
|
||||||
|
231,859,362,313,941,210,434,105,801,354,137,524,908,237,578,778,80,837,181,241
|
||||||
|
148,106,604,76,746,568,625,682,713,619,987,802,783,741,625,376,888,619,133,359
|
||||||
|
765,834,830,713,638,621,55,858,682,740,283,648,148,641,319,934,58,635,178,934
|
||||||
|
520,582,467,608,63,205,562,705,608,463,638,347,855,920,167,565,803,833,638,240
|
||||||
|
838,829,279,69,568,685,615,306,756,716,786,606,172,886,592,792,461,234,707,741
|
||||||
|
754,457,917,896,612,509,7,633,841,780,275,364,791,562,294,908,863,111,286,598
|
||||||
|
68,932,770,61,752,852,610,357,651,838,532,915,307,459,76,620,799,878,651,504
|
||||||
|
356,474,102,588,611,602,995,354,894,889,312,173,67,781,783,461,606,434,513,569
|
||||||
|
778,160,480,229,472,888,621,231,792,177,72,529,678,166,293,309,230,147,544,157
|
||||||
|
236,401,572,927,829,580,739,243,660,863,279,470,880,312,902,624,271,316,947,529
|
||||||
|
784,77,233,793,299,915,24,221,51,920,52,651,617,750,288,361,801,680,792,793
|
||||||
|
361,771,232,452,798,784,265,514,890,457,314,275,232,151,622,742,220,307,104,898
|
||||||
|
855,289,159,521,735,505,22,585,276,637,309,296,686,231,172,641,864,370,599,846
|
||||||
|
402,179,564,797,148,460,455,266,266,157,12,272,884,355,801,230,595,66,227,720
|
||||||
|
481,656,363,273,884,642,241,224,912,765,356,772,163,61,909,242,171,512,768,134
|
||||||
|
913,840,947,298,131,682,586,567,166,780,322,571,734,608,675,560,740,803,840,57
|
||||||
|
453,734,981,585,914,577,898,855,656,586,838,231,941,70,105,786,690,169,113,915
|
||||||
|
172,227,986,904,470,558,175,403,173,635,402,178,930,308,771,104,570,904,506,292
|
||||||
|
479,432,936,942,772,205,594,518,558,652,57,170,602,253,687,172,557,646,317,945
|
||||||
|
301,284,148,886,743,468,603,603,579,782,297,313,373,578,638,207,326,832,176,636
|
||||||
|
575,364,588,768,113,571,899,55,300,692,270,686,115,321,362,510,476,78,657,781
|
||||||
|
755,273,72,940,318,155,60,779,111,604,370,320,368,156,290,479,281,571,117,831
|
||||||
|
856,477,126,584,288,751,860,734,912,227,113,900,348,949,561,935,633,653,291,899
|
||||||
|
845,894,364,78,658,829,782,66,626,454,511,609,319,834,678,507,566,912,390,846
|
||||||
|
919,733,803,474,648,471,235,457,459,474,525,512,510,896,909,866,154,353,933,292
|
||||||
|
532,571,563,105,602,305,577,572,136,596,53,910,932,921,147,299,237,218,80,461
|
||||||
|
640,625,911,846,270,655,719,85,229,895,349,241,736,102,274,739,52,778,656,922
|
||||||
|
768,795,520,349,716,78,322,366,829,744,775,741,562,629,136,134,743,458,876,904
|
||||||
|
69,589,55,778,11,241,265,650,292,850,591,563,588,686,842,515,307,575,595,866
|
||||||
|
607,235,272,451,862,61,562,372,508,776,170,455,299,836,50,549,293,431,836,462
|
||||||
|
138,781,457,733,371,351,480,372,906,204,620,841,287,431,52,317,181,856,313,689
|
||||||
|
318,713,790,747,232,220,530,274,841,946,300,855,467,99,735,311,891,176,180,370
|
||||||
|
403,276,774,116,224,626,306,566,630,145,453,170,796,334,430,587,745,318,635,589
|
||||||
|
116,163,103,680,571,565,949,835,73,800,804,462,755,482,102,130,365,161,183,582
|
||||||
|
777,56,332,906,801,634,533,848,61,684,610,920,75,625,772,236,571,466,177,678
|
||||||
|
768,834,632,783,56,434,643,624,896,311,291,715,372,122,109,163,913,511,598,910
|
||||||
|
124,629,685,714,508,110,613,64,802,314,132,600,745,172,104,569,914,849,581,310
|
||||||
|
476,561,842,624,284,70,316,308,115,640,529,708,893,313,793,631,109,458,599,628
|
||||||
|
915,352,865,831,882,75,561,933,290,224,560,885,82,910,536,221,317,435,283,606
|
||||||
|
320,832,624,221,164,129,635,518,680,805,831,755,745,781,89,888,830,305,719,220
|
||||||
|
160,291,108,58,225,786,270,356,892,282,623,363,794,514,885,164,171,468,241,13
|
||||||
|
563,845,920,76,881,772,867,374,314,453,644,555,932,307,57,773,90,801,459,863
|
||||||
|
908,611,8,365,690,602,523,358,846,319,747,117,642,51,834,570,921,308,629,290
|
||||||
|
909,168,631,802,787,354,164,940,888,864,694,294,891,790,798,837,733,610,163,654
|
||||||
|
685,403,571,851,116,666,64,746,469,904,932,864,932,830,933,617,367,365,294,750
|
||||||
|
644,935,296,772,306,681,204,80,838,322,851,713,82,579,742,861,171,276,590,508
|
||||||
|
616,482,911,783,865,355,73,66,306,853,833,463,679,303,456,889,701,148,504,308
|
||||||
|
74,838,942,755,287,73,299,299,103,268,917,107,631,508,348,401,290,831,151,75
|
||||||
|
587,129,130,690,922,77,847,732,52,746,640,466,467,358,634,621,681,678,679,105
|
||||||
|
374,864,531,910,428,896,659,180,51,793,455,651,752,547,304,647,755,473,266,298
|
||||||
|
280,843,714,592,609,850,436,288,59,481,528,649,74,295,129,715,683,125,796,229
|
||||||
|
173,222,927,61,591,83,611,270,164,362,461,599,66,837,282,451,55,350,207,149
|
||||||
|
347,117,687,235,777,584,99,101,518,275,83,563,528,718,883,636,205,168,593,54
|
||||||
|
308,72,284,243,804,476,589,73,584,932,431,949,111,640,54,347,885,701,846,948
|
||||||
|
924,374,59,570,633,646,451,468,564,466,556,361,102,591,363,239,646,526,621,575
|
||||||
|
681,894,470,903,71,631,938,528,610,352,56,174,636,84,208,524,846,165,366,557
|
||||||
|
513,898,462,903,893,238,556,799,172,720,761,478,563,286,274,838,880,73,315,56
|
||||||
|
510,54,842,300,784,596,715,854,685,635,225,799,284,688,775,653,862,766,798,158
|
||||||
|
834,281,776,287,479,841,887,464,474,85,71,518,521,853,347,128,106,596,104,305
|
||||||
|
791,843,373,456,562,805,146,592,583,66,893,631,756,182,908,872,561,234,618,777
|
||||||
|
947,207,735,464,601,872,355,67,53,770,749,511,234,281,948,620,347,654,831,893
|
||||||
|
64,101,570,656,102,361,114,904,268,850,915,639,353,109,478,169,768,892,330,799
|
||||||
|
282,4,574,180,159,231,348,849,177,854,904,311,660,579,688,105,429,746,781,60
|
||||||
|
613,166,228,745,768,687,462,785,737,52,880,862,221,468,151,267,530,170,477,596
|
||||||
|
647,865,914,603,614,587,228,589,76,895,53,732,349,871,230,366,274,628,434,480
|
||||||
|
645,509,165,533,774,54,801,852,458,401,270,656,555,605,644,150,666,798,636,588
|
||||||
|
931,896,832,61,592,281,231,865,782,233,157,238,74,899,944,847,608,431,923,302
|
||||||
|
77,102,145,302,771,463,652,75,477,60,680,480,938,556,865,642,372,684,798,334
|
||||||
|
944,269,271,618,160,473,319,274,937,223,609,678,233,937,933,129,518,266,105,762
|
||||||
|
792,847,750,620,181,862,242,937,529,785,750,884,226,84,129,756,829,302,820,180
|
||||||
|
738,738,689,793,460,730,888,370,940,147,533,645,900,113,103,223,656,721,614,607
|
||||||
|
403,465,736,57,132,511,590,685,172,513,291,586,178,604,324,748,860,683,278,847
|
||||||
|
70,773,68,167,706,652,891,890,468,165,229,945,745,364,315,54,461,233,595,740
|
||||||
|
101,860,908,657,578,462,50,54,648,927,57,745,899,781,752,688,623,112,506,908
|
||||||
|
162,112,648,891,270,752,363,182,293,293,542,309,751,829,830,240,222,896,932,366
|
||||||
|
288,636,751,795,275,399,846,507,680,55,681,130,351,935,851,897,360,531,224,111
|
||||||
|
230,109,996,586,267,804,54,220,949,832,563,921,233,606,304,80,240,601,181,358
|
||||||
|
86,277,292,476,52,778,898,107,890,374,82,289,168,912,314,21,771,843,436,318
|
||||||
|
889,460,561,354,750,165,301,355,803,387,689,146,893,610,523,577,354,468,745,532
|
||||||
|
525,436,481,847,160,594,566,453,893,839,166,508,78,842,633,135,843,748,110,199
|
||||||
|
741,893,163,906,591,589,713,378,739,946,689,613,311,308,901,778,86,297,531,864
|
||||||
|
684,303,170,635,504,433,929,605,158,222,570,896,641,587,721,238,207,860,460,80
|
||||||
|
369,277,634,227,102,605,354,884,684,294,83,766,682,107,557,639,732,569,933,470
|
||||||
|
105,559,237,459,931,755,428,829,720,653,839,831,992,679,582,163,431,609,278,919
|
||||||
|
137,358,512,399,842,800,786,660,617,52,648,916,71,626,752,685,293,790,659,586
|
||||||
|
595,847,657,613,362,834,612,834,747,645,104,6,596,282,506,732,583,737,845,224
|
||||||
|
903,179,312,678,609,120,934,597,312,473,884,224,456,467,77,858,526,452,355,620
|
||||||
|
462,609,311,78,771,930,913,433,283,840,640,559,981,609,640,682,61,575,778,228
|
||||||
|
179,17,74,783,147,403,596,905,478,628,290,520,907,774,267,625,622,912,849,372
|
||||||
|
611,511,529,745,115,681,58,765,462,163,946,948,72,575,915,234,883,587,77,937
|
||||||
|
103,775,276,170,364,363,656,178,528,689,128,643,66,173,713,274,55,72,630,891
|
||||||
|
573,918,561,158,772,450,736,600,564,914,361,617,180,207,228,154,281,473,277,745
|
||||||
|
858,643,843,136,834,132,800,348,627,403,689,307,75,286,931,294,750,200,505,227
|
||||||
|
895,630,57,288,295,319,214,162,863,784,354,733,279,646,890,111,467,572,911,562
|
||||||
|
113,53,276,583,842,323,322,747,368,617,367,462,79,367,859,301,624,293,720,612
|
||||||
|
527,308,116,430,311,848,223,530,887,563,107,471,652,105,286,881,217,518,241,286
|
||||||
|
531,402,478,526,146,296,936,942,353,289,87,719,314,804,604,606,905,646,300,74
|
||||||
|
308,626,943,737,291,520,73,76,853,613,239,164,431,271,505,113,229,328,316,177
|
||||||
|
904,379,129,945,887,145,773,66,655,916,642,784,80,162,734,855,575,279,276,719
|
||||||
|
603,518,831,626,207,135,622,800,581,310,76,938,832,837,128,617,349,360,472,792
|
||||||
|
867,478,605,603,55,802,449,362,660,646,623,515,769,636,163,771,574,547,755,719
|
||||||
|
1,75,732,453,637,353,86,746,370,130,769,648,60,348,643,531,310,131,453,892
|
||||||
|
317,60,747,516,586,475,373,604,356,860,465,590,641,764,514,690,659,563,737,567
|
||||||
|
733,939,771,893,267,200,680,221,590,792,769,61,916,653,362,360,912,855,138,916
|
||||||
|
940,855,713,85,507,601,674,652,616,283,234,238,567,613,744,627,79,593,66,848
|
||||||
|
300,114,852,911,736,110,627,8,287,459,652,746,181,849,63,734,746,558,617,156
|
||||||
|
80,401,619,636,355,912,245,166,656,919,528,623,738,163,794,744,800,844,233,474
|
||||||
|
700,150,740,785,51,178,576,112,505,115,642,735,240,101,786,578,646,506,367,521
|
||||||
|
437,472,82,114,316,942,641,101,293,86,991,476,369,429,801,360,792,888,635,458
|
||||||
|
573,721,233,568,131,720,559,980,861,592,798,180,79,83,773,749,239,312,133,590
|
||||||
|
947,883,479,657,72,303,772,129,889,864,117,149,892,899,273,465,198,510,180,147
|
||||||
|
52,476,709,451,939,831,530,53,756,171,147,582,627,376,295,719,601,175,655,790
|
||||||
|
769,103,572,732,567,984,522,274,894,160,831,370,774,294,592,655,281,525,594,311
|
||||||
|
478,508,568,241,690,851,324,633,288,890,350,614,846,568,743,135,68,572,781,771
|
||||||
|
641,227,556,316,573,306,635,300,596,930,18,647,569,596,307,480,637,80,921,162
|
||||||
|
54,587,304,884,993,934,947,469,375,638,284,772,480,401,314,289,593,347,597,743
|
||||||
|
718,797,884,364,797,356,930,121,750,797,529,743,520,313,681,566,181,658,457,113
|
||||||
|
179,557,372,911,133,224,639,620,288,181,116,853,19,375,173,511,598,933,612,243
|
||||||
|
994,781,579,887,79,829,946,616,352,750,221,377,639,523,583,733,581,598,526,229
|
||||||
|
630,610,948,278,206,361,945,990,902,510,882,372,830,458,770,838,531,62,238,867
|
||||||
|
911,619,655,721,660,105,721,854,523,686,946,770,470,283,630,343,917,52,829,138
|
||||||
|
602,567,580,350,457,223,851,558,888,556,732,85,843,168,626,708,930,146,55,458
|
||||||
|
831,178,944,106,296,626,521,688,277,602,800,282,353,436,862,817,860,311,556,82
|
||||||
|
279,602,658,282,897,783,61,566,656,173,479,432,934,357,805,250,460,451,353,854
|
||||||
|
240,165,829,775,237,241,173,658,299,429,60,189,619,113,583,768,149,265,453,782
|
||||||
|
843,137,227,702,316,569,857,797,111,779,67,70,681,376,161,770,468,114,531,482
|
||||||
|
449,881,322,453,631,462,69,734,129,474,481,433,907,316,871,232,319,360,299,915
|
||||||
|
372,565,136,720,658,894,66,891,557,624,225,381,373,910,274,795,533,777,106,931
|
||||||
|
940,891,450,105,461,58,574,682,737,322,479,719,734,52,402,285,157,377,67,22
|
||||||
|
299,916,933,801,101,801,110,453,895,748,165,103,774,558,715,374,461,746,282,539
|
||||||
|
680,178,107,911,636,656,758,638,521,150,504,619,776,168,276,221,274,582,148,313
|
||||||
|
159,205,354,517,519,239,525,601,629,586,276,277,773,735,736,311,557,783,314,378
|
||||||
|
640,74,450,563,829,77,627,607,781,120,84,477,863,270,938,743,801,754,907,639
|
||||||
|
63,560,173,194,462,746,103,683,797,239,889,515,633,862,279,642,173,644,508,402
|
||||||
|
175,854,450,804,686,847,408,164,510,372,355,575,269,633,786,274,277,471,306,512
|
||||||
|
364,433,386,755,102,881,109,885,567,111,734,592,129,451,564,436,129,349,351,457
|
||||||
|
131,591,646,650,597,476,130,938,471,687,372,524,562,103,264,634,77,148,474,781
|
||||||
|
293,288,642,931,849,933,994,352,581,373,175,741,320,935,73,319,556,136,788,949
|
||||||
|
642,791,838,369,689,363,937,80,687,840,480,596,861,589,684,625,363,623,363,123
|
||||||
|
684,515,862,719,623,297,583,570,593,67,556,797,859,476,699,558,475,753,231,107
|
||||||
|
234,882,373,647,901,173,729,660,648,515,842,625,611,117,110,936,160,275,776,947
|
||||||
|
802,360,599,353,526,164,930,836,526,223,172,904,605,896,222,314,53,911,257,845
|
||||||
|
838,599,839,276,903,889,133,653,947,688,114,897,801,998,559,936,229,169,555,897
|
||||||
|
465,606,356,370,802,748,156,860,62,103,473,278,482,832,893,995,436,654,598,616
|
||||||
|
599,129,611,770,303,843,563,751,855,587,593,515,641,647,831,301,586,660,760,81
|
||||||
|
166,361,775,377,576,575,239,76,768,465,612,750,593,471,157,680,923,239,885,458
|
||||||
|
299,716,564,504,713,527,797,533,587,605,436,235,138,107,852,791,638,403,121,593
|
||||||
|
738,505,240,569,149,918,140,656,156,318,631,848,754,278,841,911,599,70,916,55
|
||||||
|
181,690,278,569,434,838,182,453,855,653,271,597,990,941,533,774,840,746,268,103
|
||||||
|
60,60,612,752,913,592,689,469,592,686,785,768,278,916,505,656,355,606,890,19
|
||||||
|
532,355,633,480,135,493,621,157,82,902,75,135,468,302,597,435,900,287,862,901
|
||||||
|
734,781,891,65,428,740,691,71,66,177,464,558,682,352,571,60,300,571,148,601
|
||||||
|
687,372,146,464,516,109,549,738,521,135,236,59,314,229,402,918,656,137,921,629
|
||||||
|
199,453,533,356,296,905,308,629,633,911,369,459,569,587,739,367,899,233,482,112
|
||||||
|
836,778,136,478,505,657,164,858,947,526,639,273,365,366,785,745,854,398,852,74
|
||||||
|
625,939,86,243,771,117,119,517,651,66,265,643,66,310,864,310,305,626,732,849
|
||||||
|
624,621,887,467,573,761,589,612,648,883,355,432,451,515,281,67,780,601,162,465
|
||||||
|
632,240,761,881,782,593,110,856,783,900,844,52,282,634,276,836,293,271,579,895
|
||||||
|
913,720,514,743,241,434,786,929,800,920,948,179,883,607,68,903,129,481,779,512
|
||||||
|
732,642,893,625,509,310,70,319,101,904,113,373,136,132,555,988,619,734,744,587
|
||||||
|
171,929,829,85,656,884,281,744,226,229,104,844,430,276,157,228,83,866,283,273
|
||||||
|
988,133,594,175,452,162,575,678,627,606,625,512,660,436,116,842,582,300,635,594
|
||||||
|
167,461,194,884,357,206,55,77,858,369,802,745,887,779,305,613,576,789,600,170
|
||||||
|
562,461,429,275,636,589,651,106,55,526,989,581,920,577,798,373,429,773,464,772
|
||||||
|
917,858,606,288,733,356,284,234,865,476,925,919,804,227,507,55,914,301,567,149
|
||||||
|
269,685,521,56,850,310,364,609,296,15,67,646,52,513,350,241,458,652,745,85
|
||||||
|
782,163,352,242,610,560,380,106,659,284,312,898,180,896,289,475,62,835,897,117
|
||||||
|
690,791,780,133,910,598,85,595,834,83,373,238,450,580,907,761,783,785,855,741
|
||||||
|
638,279,348,782,749,71,891,586,353,105,867,565,354,924,310,562,930,680,911,243
|
||||||
|
59,947,70,859,865,116,648,326,794,941,845,169,241,898,775,786,917,315,280,566
|
||||||
|
913,522,166,790,361,453,848,146,604,354,162,101,844,456,772,914,997,163,907,898
|
||||||
|
308,934,175,804,775,166,352,55,833,343,368,860,457,948,862,288,62,841,229,181
|
||||||
|
636,605,591,687,376,911,782,461,101,721,402,449,615,269,146,777,71,838,347,672
|
||||||
|
921,510,530,428,461,139,904,105,862,679,322,579,858,283,453,301,897,52,402,589
|
||||||
|
747,605,634,584,67,715,886,278,570,524,299,721,308,890,300,607,231,478,90,902
|
||||||
|
348,681,631,358,830,635,228,468,105,717,768,908,300,750,224,515,110,642,867,696
|
||||||
|
171,477,284,508,117,72,681,568,896,841,77,846,555,355,721,591,296,668,308,113
|
||||||
|
268,936,936,932,318,274,582,517,849,635,282,168,858,678,932,280,760,804,357,714
|
||||||
|
232,921,859,456,505,361,678,645,467,79,153,302,353,915,313,449,932,949,801,130
|
||||||
|
838,532,913,116,529,905,612,575,236,947,567,533,520,171,765,569,829,883,942,364
|
||||||
|
242,569,522,578,597,570,457,314,133,274,301,775,910,644,168,209,138,558,173,297
|
||||||
|
883,511,297,366,114,595,299,642,77,52,54,840,284,661,318,282,278,591,647,641
|
||||||
|
17,840,847,220,347,304,177,720,840,840,653,946,376,181,481,629,633,172,365,680
|
||||||
|
222,945,839,160,678,353,299,587,476,532,743,101,477,936,316,204,402,225,790,519
|
||||||
|
226,479,62,617,159,66,785,588,990,521,156,361,685,656,754,769,482,930,913,167
|
||||||
|
769,109,753,747,226,705,274,844,85,609,148,316,52,181,689,632,612,595,307,931
|
||||||
|
558,805,88,106,372,754,222,756,838,475,471,844,482,884,299,769,232,589,802,789
|
||||||
|
683,305,744,451,531,718,307,276,146,886,525,802,233,395,622,775,302,935,889,61
|
||||||
|
294,612,573,524,365,108,562,289,76,134,743,321,58,771,718,294,271,938,729,787
|
||||||
|
739,559,237,794,278,178,575,464,568,916,436,929,352,859,619,794,582,361,769,745
|
||||||
|
382,131,862,356,525,286,457,886,718,241,456,180,312,173,295,581,179,616,57,375
|
||||||
|
592,226,740,276,351,837,518,224,478,403,610,462,69,354,789,367,982,178,804,481
|
||||||
|
773,582,310,684,656,450,687,145,532,937,752,901,280,206,748,300,945,235,986,134
|
||||||
|
436,944,296,581,685,228,321,847,363,133,605,934,156,842,116,388,464,275,137,145
|
||||||
|
451,584,105,933,621,922,618,316,732,568,679,229,307,591,363,920,223,577,106,454
|
||||||
|
678,732,376,372,457,910,155,476,835,753,656,54,294,829,432,312,312,853,521,130
|
||||||
|
303,685,543,471,851,451,910,573,354,558,687,372,753,78,746,372,657,753,348,168
|
||||||
|
646,115,224,891,800,788,237,565,900,602,51,165,179,653,656,769,303,926,80,780
|
||||||
|
736,354,768,585,796,919,612,309,743,163,357,892,616,628,83,88,60,751,714,103
|
||||||
|
229,615,842,772,775,620,859,90,920,294,643,921,740,277,916,577,839,107,600,746
|
||||||
|
931,177,590,462,558,89,353,476,640,930,779,575,591,719,307,167,527,403,846,429
|
||||||
|
921,795,51,303,596,720,741,720,571,649,572,67,366,350,935,925,900,521,431,772
|
||||||
|
505,467,561,609,678,611,601,220,104,915,269,864,169,778,580,847,654,364,899,991
|
||||||
|
592,600,432,64,450,801,353,592,645,714,228,754,929,287,862,578,560,506,451,846
|
||||||
|
179,621,178,606,366,896,844,363,611,220,618,277,367,243,455,916,127,738,888,866
|
||||||
|
63,520,291,785,932,777,788,801,295,788,301,717,655,362,844,265,584,718,798,993
|
||||||
|
51,294,348,111,935,640,633,639,533,936,138,224,166,228,358,113,205,92,436,377
|
||||||
|
900,916,160,865,515,537,803,679,589,149,282,528,349,82,136,451,750,130,507,114
|
||||||
|
741,948,278,604,848,355,750,506,741,175,780,850,232,361,785,228,848,556,219,936
|
||||||
|
76,805,451,286,832,565,774,943,515,317,626,719,473,678,114,21,504,890,471,852
|
||||||
|
525,734,932,681,715,461,612,179,613,633,738,838,560,208,942,564,637,300,789,432
|
||||||
|
805,74,620,838,559,555,82,845,50,0,784,681,368,897,906,636,508,600,163,137
|
||||||
|
431,86,792,55,61,466,825,467,652,60,377,581,747,159,530,347,131,682,237,626
|
||||||
|
53,350,632,838,601,374,606,891,831,164,781,453,5,583,63,273,558,522,585,598
|
||||||
|
54,755,629,312,530,420,641,831,628,574,310,626,358,476,463,150,130,688,268,531
|
||||||
|
737,800,859,157,685,365,604,312,907,313,783,513,533,230,648,472,884,509,672,720
|
||||||
|
713,349,241,457,106,449,474,885,79,481,721,233,936,831,913,772,381,946,57,832
|
||||||
|
931,362,944,482,930,374,650,654,942,890,676,83,355,117,377,747,508,717,243,931
|
||||||
|
172,116,843,274,220,836,837,360,645,295,138,772,302,179,51,362,464,80,515,986
|
||||||
|
569,83,658,159,842,359,114,156,911,756,398,848,286,583,629,749,455,776,456,69
|
||||||
|
641,900,180,352,608,620,948,117,309,639,190,891,894,319,294,651,860,310,638,532
|
||||||
|
631,937,274,907,150,0,773,526,733,794,476,275,113,169,311,863,795,358,403,516
|
||||||
|
508,780,181,603,846,802,231,472,513,109,649,239,680,679,389,916,437,512,401,285
|
||||||
|
148,402,303,591,639,826,630,683,243,633,686,473,940,295,743,280,475,163,573,291
|
||||||
|
518,690,62,115,351,795,555,854,322,740,627,68,641,171,646,639,20,159,181,72
|
||||||
|
86,321,166,790,853,175,310,513,80,133,771,658,629,707,789,914,174,292,574,375
|
||||||
|
224,455,524,315,364,589,582,101,743,159,166,647,304,316,455,19,647,562,170,745
|
||||||
|
51,55,105,306,517,906,830,319,638,233,940,520,277,470,810,638,634,428,657,933
|
||||||
|
656,172,638,571,145,249,101,831,234,454,114,848,269,402,627,65,749,371,901,932
|
||||||
|
718,82,527,376,180,592,630,132,280,850,910,528,279,224,922,857,430,746,716,133
|
||||||
|
78,631,173,228,365,888,733,774,741,298,771,830,358,167,198,690,348,901,798,241
|
||||||
|
883,238,402,796,740,103,919,194,294,355,634,579,586,69,56,270,746,63,74,589
|
||||||
|
285,946,777,514,132,627,648,179,619,235,432,606,830,193,171,909,720,682,581,784
|
||||||
|
271,111,644,883,895,583,227,270,773,921,291,321,371,303,559,667,352,529,320,457
|
||||||
|
716,364,112,449,227,618,797,747,573,802,588,304,801,679,169,788,742,856,987,797
|
||||||
|
507,310,480,146,451,793,769,720,738,164,753,172,459,936,67,516,287,468,734,88
|
||||||
|
579,291,240,163,906,509,138,79,556,60,605,851,655,296,86,437,916,153,298,910
|
||||||
|
401,505,599,652,588,161,877,782,530,882,623,362,805,851,748,135,842,59,508,308
|
||||||
|
895,691,751,57,156,841,932,520,146,366,714,890,561,772,636,367,716,111,296,625
|
||||||
|
690,359,853,775,7,57,53,222,279,590,70,321,660,71,585,643,782,72,920,111
|
||||||
|
597,753,166,563,180,512,68,794,861,510,718,308,525,979,848,862,689,376,565,271
|
||||||
|
355,845,802,234,472,920,174,62,945,889,715,110,721,900,917,948,866,461,140,787
|
160
www/statics/aoc/2020/16_solution.rs
Normal file
160
www/statics/aoc/2020/16_solution.rs
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
use crate::common::AdventOfCodeDay;
|
||||||
|
|
||||||
|
#[derive(Debug,Clone)]
|
||||||
|
pub struct Day16 {
|
||||||
|
rules: Vec<Rule>,
|
||||||
|
ticket: RawTicketData,
|
||||||
|
nearby: Vec<RawTicketData>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone)]
|
||||||
|
struct Rule {
|
||||||
|
name: String,
|
||||||
|
ranges: Vec<(i32, i32)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rule {
|
||||||
|
fn matches(&self, dat: i32) -> bool {
|
||||||
|
return self.ranges.iter().any(|(lower, upper)| dat >= *lower && dat <= *upper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone)]
|
||||||
|
struct RawTicketData {
|
||||||
|
fields: Vec<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day16 {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let input_bytes = include_bytes!("../res/16_input.txt");
|
||||||
|
let input_str = String::from_utf8_lossy(input_bytes);
|
||||||
|
|
||||||
|
let lines = input_str
|
||||||
|
.lines()
|
||||||
|
.map(|p| String::from(p))
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
|
let mut rules: Vec<Rule> = Vec::new();
|
||||||
|
loop {
|
||||||
|
let line = lines[i].clone();
|
||||||
|
if line == "" { i+=1; i+=1; break; }
|
||||||
|
|
||||||
|
let s1 = line.split(": ").collect::<Vec<&str>>();
|
||||||
|
let name = s1[0].to_owned();
|
||||||
|
|
||||||
|
let s2 = s1[1].split(" or ").collect::<Vec<&str>>();
|
||||||
|
|
||||||
|
let s21 = s2[0].split('-').collect::<Vec<&str>>();
|
||||||
|
let range1 = (s21[0].parse::<i32>().unwrap(), s21[1].parse::<i32>().unwrap());
|
||||||
|
|
||||||
|
let s22 = s2[1].split('-').collect::<Vec<&str>>();
|
||||||
|
let range2 = (s22[0].parse::<i32>().unwrap(), s22[1].parse::<i32>().unwrap());
|
||||||
|
|
||||||
|
rules.push(Rule {
|
||||||
|
name: name,
|
||||||
|
ranges: vec![ range1, range2 ],
|
||||||
|
});
|
||||||
|
|
||||||
|
i+=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let myticket = RawTicketData {
|
||||||
|
fields: lines[i].split(',').map(|p| p.parse::<i32>().unwrap()).collect(),
|
||||||
|
};
|
||||||
|
i+=1;
|
||||||
|
|
||||||
|
i+=1;
|
||||||
|
i+=1;
|
||||||
|
|
||||||
|
let mut nearbytickets: Vec<RawTicketData> = Vec::new();
|
||||||
|
while i < lines.len() {
|
||||||
|
|
||||||
|
nearbytickets.push(RawTicketData {
|
||||||
|
fields: lines[i].split(',').map(|p| p.parse::<i32>().unwrap()).collect(),
|
||||||
|
});
|
||||||
|
|
||||||
|
i+=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Self {
|
||||||
|
rules: rules,
|
||||||
|
ticket: myticket,
|
||||||
|
nearby: nearbytickets,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AdventOfCodeDay for Day16 {
|
||||||
|
|
||||||
|
fn task_1(&self) -> String {
|
||||||
|
return self.nearby
|
||||||
|
.iter()
|
||||||
|
.flat_map(|p| p.fields.iter())
|
||||||
|
.filter(|f| self.rules.iter().all(|r| !r.matches(**f)))
|
||||||
|
.sum::<i32>()
|
||||||
|
.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn task_2(&self) -> String {
|
||||||
|
|
||||||
|
let valid = self.nearby
|
||||||
|
.iter()
|
||||||
|
.filter(|p| p.fields.iter().all(|f| self.rules.iter().any(|r| r.matches(*f))))
|
||||||
|
.map(|p| p.clone())
|
||||||
|
.collect::<Vec<RawTicketData>>();
|
||||||
|
|
||||||
|
let mut candidates: Vec<(Rule, Vec<usize>)>;
|
||||||
|
candidates = self.rules
|
||||||
|
.iter()
|
||||||
|
.map(|rule| (rule.clone(), (0..self.ticket.fields.len())
|
||||||
|
.filter(|i| rule.matches(self.ticket.fields[*i]))
|
||||||
|
.filter(|i| valid.iter().all(|d| rule.matches(d.fields[*i]) ) )
|
||||||
|
.map(|p| p.clone())
|
||||||
|
.collect::<Vec<usize>>()))
|
||||||
|
.collect::<Vec<(Rule, Vec<usize>)>>();
|
||||||
|
|
||||||
|
verboseln!();
|
||||||
|
if is_verbose!() { for c in &candidates { verboseln!("{}: {:?}", c.0.name, c.1); } }
|
||||||
|
verboseln!();
|
||||||
|
|
||||||
|
while candidates.iter().any(|c| c.1.len() != 1) {
|
||||||
|
|
||||||
|
let rm = candidates.iter()
|
||||||
|
.filter(|c| c.1.len() == 1)
|
||||||
|
.flat_map(|p| p.1.iter())
|
||||||
|
.filter(|p| candidates.iter().filter(|c| c.1.contains(p)).count() > 1)
|
||||||
|
.map(|p|p.clone())
|
||||||
|
.collect::<Vec<usize>>();
|
||||||
|
|
||||||
|
// Field {rm} is teh single candidate of a rule and so it can not be a candidate for any other rule
|
||||||
|
verboseln!("Remove {:?}", rm);
|
||||||
|
for c in candidates.iter_mut().filter(|c| c.1.len() > 1) { c.1.retain(|v| !rm.contains(v) ); }
|
||||||
|
|
||||||
|
let unique = (0..self.ticket.fields.len())
|
||||||
|
.filter(|i| candidates.iter().filter(|c| c.1.contains(i)).count() == 1)
|
||||||
|
.filter(|i| candidates.iter().filter(|c| c.1.contains(i) && c.1.len() > 1).count() == 1)
|
||||||
|
.map(|p|p.clone())
|
||||||
|
.collect::<Vec<usize>>();
|
||||||
|
|
||||||
|
// Field {uniq} only appears in one rule and so it must be the candidate for that rule
|
||||||
|
verboseln!("Clean {:?}", unique);
|
||||||
|
for ui in &unique {
|
||||||
|
for c in candidates.iter_mut().filter(|c| c.1.contains(ui)) { c.1.retain(|v| v == ui ); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verboseln!();
|
||||||
|
if is_verbose!() { for c in &candidates { verboseln!("{}: {:?} => {}", c.0.name, c.1, self.ticket.fields[c.1[0]]); } }
|
||||||
|
verboseln!();
|
||||||
|
|
||||||
|
return candidates.iter()
|
||||||
|
.filter(|c| c.0.name.starts_with("departure"))
|
||||||
|
.map(|c| c.1[0])
|
||||||
|
.map(|i| self.ticket.fields[i])
|
||||||
|
.map(|v| v as u128)
|
||||||
|
.fold(1, |a,b| a*b)
|
||||||
|
.to_string();
|
||||||
|
}
|
||||||
|
}
|
394
www/statics/aoc/2020/17_challenge.txt
Normal file
394
www/statics/aoc/2020/17_challenge.txt
Normal file
@ -0,0 +1,394 @@
|
|||||||
|
As your flight slowly drifts through the sky, the Elves at the Mythical Information Bureau at the North Pole contact you. They'd like some help debugging a malfunctioning experimental energy source aboard one of their super-secret imaging satellites.
|
||||||
|
|
||||||
|
The experimental energy source is based on cutting-edge technology: a set of Conway Cubes contained in a pocket dimension! When you hear it's having problems, you can't help but agree to take a look.
|
||||||
|
|
||||||
|
The pocket dimension contains an infinite 3-dimensional grid. At every integer 3-dimensional coordinate (x,y,z), there exists a single cube which is either active or inactive.
|
||||||
|
|
||||||
|
In the initial state of the pocket dimension, almost all cubes start inactive. The only exception to this is a small flat region of cubes (your puzzle input); the cubes in this region start in the specified active (#) or inactive (.) state.
|
||||||
|
|
||||||
|
The energy source then proceeds to boot up by executing six cycles.
|
||||||
|
|
||||||
|
Each cube only ever considers its neighbors: any of the 26 other cubes where any of their coordinates differ by at most 1. For example, given the cube at x=1,y=2,z=3, its neighbors include the cube at x=2,y=2,z=2, the cube at x=0,y=2,z=3, and so on.
|
||||||
|
|
||||||
|
During a cycle, all cubes simultaneously change their state according to the following rules:
|
||||||
|
|
||||||
|
If a cube is active and exactly 2 or 3 of its neighbors are also active, the cube remains active. Otherwise, the cube becomes inactive.
|
||||||
|
If a cube is inactive but exactly 3 of its neighbors are active, the cube becomes active. Otherwise, the cube remains inactive.
|
||||||
|
|
||||||
|
The engineers responsible for this experimental energy source would like you to simulate the pocket dimension and determine what the configuration of cubes should be at the end of the six-cycle boot process.
|
||||||
|
|
||||||
|
For example, consider the following initial state:
|
||||||
|
|
||||||
|
.#.
|
||||||
|
..#
|
||||||
|
###
|
||||||
|
|
||||||
|
Even though the pocket dimension is 3-dimensional, this initial state represents a small 2-dimensional slice of it. (In particular, this initial state defines a 3x3x1 region of the 3-dimensional space.)
|
||||||
|
|
||||||
|
Simulating a few cycles from this initial state produces the following configurations, where the result of each cycle is shown layer-by-layer at each given z coordinate (and the frame of view follows the active cells in each cycle):
|
||||||
|
|
||||||
|
Before any cycles:
|
||||||
|
|
||||||
|
z=0
|
||||||
|
.#.
|
||||||
|
..#
|
||||||
|
###
|
||||||
|
|
||||||
|
|
||||||
|
After 1 cycle:
|
||||||
|
|
||||||
|
z=-1
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=0
|
||||||
|
#.#
|
||||||
|
.##
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=1
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
|
||||||
|
After 2 cycles:
|
||||||
|
|
||||||
|
z=-2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
..#..
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=-1
|
||||||
|
..#..
|
||||||
|
.#..#
|
||||||
|
....#
|
||||||
|
.#...
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=0
|
||||||
|
##...
|
||||||
|
##...
|
||||||
|
#....
|
||||||
|
....#
|
||||||
|
.###.
|
||||||
|
|
||||||
|
z=1
|
||||||
|
..#..
|
||||||
|
.#..#
|
||||||
|
....#
|
||||||
|
.#...
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
..#..
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
|
||||||
|
After 3 cycles:
|
||||||
|
|
||||||
|
z=-2
|
||||||
|
.......
|
||||||
|
.......
|
||||||
|
..##...
|
||||||
|
..###..
|
||||||
|
.......
|
||||||
|
.......
|
||||||
|
.......
|
||||||
|
|
||||||
|
z=-1
|
||||||
|
..#....
|
||||||
|
...#...
|
||||||
|
#......
|
||||||
|
.....##
|
||||||
|
.#...#.
|
||||||
|
..#.#..
|
||||||
|
...#...
|
||||||
|
|
||||||
|
z=0
|
||||||
|
...#...
|
||||||
|
.......
|
||||||
|
#......
|
||||||
|
.......
|
||||||
|
.....##
|
||||||
|
.##.#..
|
||||||
|
...#...
|
||||||
|
|
||||||
|
z=1
|
||||||
|
..#....
|
||||||
|
...#...
|
||||||
|
#......
|
||||||
|
.....##
|
||||||
|
.#...#.
|
||||||
|
..#.#..
|
||||||
|
...#...
|
||||||
|
|
||||||
|
z=2
|
||||||
|
.......
|
||||||
|
.......
|
||||||
|
..##...
|
||||||
|
..###..
|
||||||
|
.......
|
||||||
|
.......
|
||||||
|
.......
|
||||||
|
|
||||||
|
After the full six-cycle boot process completes, 112 cubes are left in the active state.
|
||||||
|
|
||||||
|
Starting with your given initial configuration, simulate six cycles. How many cubes are left in the active state after the sixth cycle?
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
For some reason, your simulated results don't match what the experimental energy source engineers expected. Apparently, the pocket dimension actually has four spatial dimensions, not three.
|
||||||
|
|
||||||
|
The pocket dimension contains an infinite 4-dimensional grid. At every integer 4-dimensional coordinate (x,y,z,w), there exists a single cube (really, a hypercube) which is still either active or inactive.
|
||||||
|
|
||||||
|
Each cube only ever considers its neighbors: any of the 80 other cubes where any of their coordinates differ by at most 1. For example, given the cube at x=1,y=2,z=3,w=4, its neighbors include the cube at x=2,y=2,z=3,w=3, the cube at x=0,y=2,z=3,w=4, and so on.
|
||||||
|
|
||||||
|
The initial state of the pocket dimension still consists of a small flat region of cubes. Furthermore, the same rules for cycle updating still apply: during each cycle, consider the number of active neighbors of each cube.
|
||||||
|
|
||||||
|
For example, consider the same initial state as in the example above. Even though the pocket dimension is 4-dimensional, this initial state represents a small 2-dimensional slice of it. (In particular, this initial state defines a 3x3x1x1 region of the 4-dimensional space.)
|
||||||
|
|
||||||
|
Simulating a few cycles from this initial state produces the following configurations, where the result of each cycle is shown layer-by-layer at each given z and w coordinate:
|
||||||
|
|
||||||
|
Before any cycles:
|
||||||
|
|
||||||
|
z=0, w=0
|
||||||
|
.#.
|
||||||
|
..#
|
||||||
|
###
|
||||||
|
|
||||||
|
|
||||||
|
After 1 cycle:
|
||||||
|
|
||||||
|
z=-1, w=-1
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=0, w=-1
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=1, w=-1
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=-1, w=0
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=0, w=0
|
||||||
|
#.#
|
||||||
|
.##
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=1, w=0
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=-1, w=1
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=0, w=1
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
z=1, w=1
|
||||||
|
#..
|
||||||
|
..#
|
||||||
|
.#.
|
||||||
|
|
||||||
|
|
||||||
|
After 2 cycles:
|
||||||
|
|
||||||
|
z=-2, w=-2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
..#..
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=-1, w=-2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=0, w=-2
|
||||||
|
###..
|
||||||
|
##.##
|
||||||
|
#...#
|
||||||
|
.#..#
|
||||||
|
.###.
|
||||||
|
|
||||||
|
z=1, w=-2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=2, w=-2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
..#..
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=-2, w=-1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=-1, w=-1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=0, w=-1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=1, w=-1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=2, w=-1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=-2, w=0
|
||||||
|
###..
|
||||||
|
##.##
|
||||||
|
#...#
|
||||||
|
.#..#
|
||||||
|
.###.
|
||||||
|
|
||||||
|
z=-1, w=0
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=0, w=0
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=1, w=0
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=2, w=0
|
||||||
|
###..
|
||||||
|
##.##
|
||||||
|
#...#
|
||||||
|
.#..#
|
||||||
|
.###.
|
||||||
|
|
||||||
|
z=-2, w=1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=-1, w=1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=0, w=1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=1, w=1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=2, w=1
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=-2, w=2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
..#..
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=-1, w=2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=0, w=2
|
||||||
|
###..
|
||||||
|
##.##
|
||||||
|
#...#
|
||||||
|
.#..#
|
||||||
|
.###.
|
||||||
|
|
||||||
|
z=1, w=2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
z=2, w=2
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
..#..
|
||||||
|
.....
|
||||||
|
.....
|
||||||
|
|
||||||
|
After the full six-cycle boot process completes, 848 cubes are left in the active state.
|
||||||
|
|
||||||
|
Starting with your given initial configuration, simulate six cycles in a 4-dimensional space. How many cubes are left in the active state after the sixth cycle?
|
8
www/statics/aoc/2020/17_input.txt
Normal file
8
www/statics/aoc/2020/17_input.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.#.####.
|
||||||
|
.#...##.
|
||||||
|
..###.##
|
||||||
|
#..#.#.#
|
||||||
|
#..#....
|
||||||
|
#.####..
|
||||||
|
##.##..#
|
||||||
|
#.#.#..#
|
312
www/statics/aoc/2020/17_solution.rs
Normal file
312
www/statics/aoc/2020/17_solution.rs
Normal file
@ -0,0 +1,312 @@
|
|||||||
|
use crate::common::AdventOfCodeDay;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
pub struct Day17 {
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
input: Vec<Vec<bool>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day17 {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let input_bytes = include_bytes!("../res/17_input.txt");
|
||||||
|
let input_str = String::from_utf8_lossy(input_bytes);
|
||||||
|
|
||||||
|
let lines = input_str.lines().map(String::from).collect::<Vec<String>>();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
width: lines[0].len() as i32,
|
||||||
|
height: lines.len() as i32,
|
||||||
|
|
||||||
|
input: lines.iter().map(|l| l.chars().map(|c| c=='#').collect()).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait DimensionalCoord {
|
||||||
|
fn zero() -> Self;
|
||||||
|
|
||||||
|
fn componentwise_min(&self, other: Self) -> Self;
|
||||||
|
fn componentwise_max(&self, other: Self) -> Self;
|
||||||
|
|
||||||
|
fn inc_all(&mut self, delta: i32);
|
||||||
|
fn iter_neighbours<F>(&self, fun: F) where F: FnMut(Self), Self: Sized;
|
||||||
|
|
||||||
|
fn iter_all_coords_inclusive<F>(min: Self, max: Self, fun: F) where F: FnMut(Self), Self: Sized;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, std::hash::Hash, Clone, Copy)]
|
||||||
|
struct Coord3D {
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
z: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DimensionalCoord for Coord3D {
|
||||||
|
fn zero() -> Self {
|
||||||
|
Self {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn componentwise_min(&self, other: Self) -> Self {
|
||||||
|
Self {
|
||||||
|
x: if self.x < other.x { self.x } else { other.x },
|
||||||
|
y: if self.y < other.y { self.y } else { other.y },
|
||||||
|
z: if self.z < other.z { self.z } else { other.z },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn componentwise_max(&self, other: Self) -> Self {
|
||||||
|
Self {
|
||||||
|
x: if self.x > other.x { self.x } else { other.x },
|
||||||
|
y: if self.y > other.y { self.y } else { other.y },
|
||||||
|
z: if self.z > other.z { self.z } else { other.z },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inc_all(&mut self, delta: i32) {
|
||||||
|
self.x += delta;
|
||||||
|
self.y += delta;
|
||||||
|
self.z += delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn iter_neighbours<F>(&self, mut fun: F) where F: FnMut(Self) {
|
||||||
|
for dx in -1..=1 {
|
||||||
|
for dy in -1..=1 {
|
||||||
|
for dz in -1..=1 {
|
||||||
|
if dx==0 && dy==0 && dz==0 { continue; }
|
||||||
|
fun(Coord3D::new(self.x+dx, self.y+dy, self.z+dz));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn iter_all_coords_inclusive<F>(min: Self, max: Self, mut fun: F) where F: FnMut(Self) {
|
||||||
|
for x in min.x..=max.x {
|
||||||
|
for y in min.y..=max.y {
|
||||||
|
for z in min.z..=max.z {
|
||||||
|
fun(Coord3D::new(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Coord3D {
|
||||||
|
fn new(x:i32, y:i32, z:i32) -> Self {
|
||||||
|
Self {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(PartialEq, Eq, std::hash::Hash, Clone, Copy)]
|
||||||
|
struct Coord4D {
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
z: i32,
|
||||||
|
w: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DimensionalCoord for Coord4D {
|
||||||
|
fn zero() -> Self {
|
||||||
|
Self {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0,
|
||||||
|
w: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn componentwise_min(&self, other: Self) -> Self {
|
||||||
|
Self {
|
||||||
|
x: if self.x < other.x { self.x } else { other.x },
|
||||||
|
y: if self.y < other.y { self.y } else { other.y },
|
||||||
|
z: if self.z < other.z { self.z } else { other.z },
|
||||||
|
w: if self.w < other.w { self.w } else { other.w },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn componentwise_max(&self, other: Self) -> Self {
|
||||||
|
Self {
|
||||||
|
x: if self.x > other.x { self.x } else { other.x },
|
||||||
|
y: if self.y > other.y { self.y } else { other.y },
|
||||||
|
z: if self.z > other.z { self.z } else { other.z },
|
||||||
|
w: if self.w > other.w { self.w } else { other.w },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inc_all(&mut self, delta: i32) {
|
||||||
|
self.x += delta;
|
||||||
|
self.y += delta;
|
||||||
|
self.z += delta;
|
||||||
|
self.w += delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn iter_neighbours<F>(&self, mut fun: F) where F: FnMut(Self) {
|
||||||
|
for dx in -1..=1 {
|
||||||
|
for dy in -1..=1 {
|
||||||
|
for dz in -1..=1 {
|
||||||
|
for dw in -1..=1 {
|
||||||
|
if dx==0 && dy==0 && dz==0 && dw==0 { continue; }
|
||||||
|
fun(Coord4D::new(self.x+dx, self.y+dy, self.z+dz, self.w+dw));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn iter_all_coords_inclusive<F>(min: Self, max: Self, mut fun: F) where F: FnMut(Self) {
|
||||||
|
for x in min.x..=max.x {
|
||||||
|
for y in min.y..=max.y {
|
||||||
|
for z in min.z..=max.z {
|
||||||
|
for w in min.w..=max.w {
|
||||||
|
fun(Coord4D::new(x, y, z, w));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Coord4D {
|
||||||
|
fn new(x:i32, y:i32, z:i32, w:i32) -> Self {
|
||||||
|
Self {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
w,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PocketUniverse<TCoord: DimensionalCoord + Eq + std::hash::Hash + Clone + Copy> {
|
||||||
|
state: HashMap<TCoord, (bool, bool)>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<TCoord: DimensionalCoord + Eq + std::hash::Hash + Clone + Copy> PocketUniverse<TCoord> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
state: HashMap::with_capacity(8192),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn step(&mut self) {
|
||||||
|
let mut min_coord = TCoord::zero();
|
||||||
|
let mut max_coord = TCoord::zero();
|
||||||
|
|
||||||
|
for (c, (v_old, v_curr)) in self.state.iter_mut() {
|
||||||
|
*v_old = *v_curr;
|
||||||
|
|
||||||
|
min_coord = min_coord.componentwise_min(*c);
|
||||||
|
max_coord = max_coord.componentwise_max(*c);
|
||||||
|
}
|
||||||
|
|
||||||
|
min_coord.inc_all(-1);
|
||||||
|
max_coord.inc_all(1);
|
||||||
|
|
||||||
|
TCoord::iter_all_coords_inclusive(min_coord.clone(), max_coord.clone(), |c| self.step_single(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn step_single(&mut self, c: TCoord) {
|
||||||
|
|
||||||
|
let nbc = self.get_neighbours_old(c);
|
||||||
|
|
||||||
|
if self.get_old(c) {
|
||||||
|
|
||||||
|
if nbc == 2 || nbc == 3 {
|
||||||
|
// stay active
|
||||||
|
} else {
|
||||||
|
self.set_new(c, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if nbc == 3 {
|
||||||
|
self.set_new(c, true);
|
||||||
|
} else {
|
||||||
|
// remain inactive
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_old(&self, c: TCoord) -> bool {
|
||||||
|
if let Some((v_old, _)) = self.state.get(&c) {
|
||||||
|
return *v_old;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_neighbours_old(&self, c: TCoord) -> i32 {
|
||||||
|
let mut count = 0;
|
||||||
|
|
||||||
|
c.iter_neighbours(|c| {
|
||||||
|
if self.get_old(c) {
|
||||||
|
count+=1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_new(&mut self, c: TCoord, v: bool) {
|
||||||
|
if let Some((_, v_new)) = self.state.get_mut(&c) {
|
||||||
|
*v_new = v;
|
||||||
|
} else {
|
||||||
|
self.state.insert(c, (false, v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn count_active_new(&self) -> i32 {
|
||||||
|
return self.state.iter().filter(|(_,v)| v.1).count() as i32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AdventOfCodeDay for Day17 {
|
||||||
|
|
||||||
|
fn task_1(&self) -> String {
|
||||||
|
|
||||||
|
let mut pock_uni = PocketUniverse::<Coord3D>::new();
|
||||||
|
|
||||||
|
for x in 0..self.width {
|
||||||
|
for y in 0..self.height {
|
||||||
|
pock_uni.state.insert(Coord3D::new(x,y,0), (false, self.input[y as usize][x as usize]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verboseln!("After 0 cycles:");
|
||||||
|
verboseln!("{}", pock_uni.count_active_new());
|
||||||
|
verboseln!();
|
||||||
|
|
||||||
|
for i in 0..6 {
|
||||||
|
pock_uni.step();
|
||||||
|
|
||||||
|
verboseln!("After {} cycles:", i+1);
|
||||||
|
verboseln!("{}", pock_uni.count_active_new());
|
||||||
|
verboseln!();
|
||||||
|
}
|
||||||
|
|
||||||
|
return pock_uni.count_active_new().to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn task_2(&self) -> String {
|
||||||
|
let mut pock_uni = PocketUniverse::<Coord4D>::new();
|
||||||
|
|
||||||
|
for x in 0..self.width {
|
||||||
|
for y in 0..self.height {
|
||||||
|
pock_uni.state.insert(Coord4D::new(x,y,0,0), (false, self.input[y as usize][x as usize]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _ in 0..6 { pock_uni.step(); }
|
||||||
|
|
||||||
|
return pock_uni.count_active_new().to_string();
|
||||||
|
}
|
||||||
|
}
|
59
www/statics/aoc/2020/18_challenge.txt
Normal file
59
www/statics/aoc/2020/18_challenge.txt
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
As you look out the window and notice a heavily-forested continent slowly appear over the horizon, you are interrupted by the child sitting next to you. They're curious if you could help them with their math homework.
|
||||||
|
|
||||||
|
Unfortunately, it seems like this "math" follows different rules than you remember.
|
||||||
|
|
||||||
|
The homework (your puzzle input) consists of a series of expressions that consist of addition (+), multiplication (*), and parentheses ((...)). Just like normal math, parentheses indicate that the expression inside must be evaluated before it can be used by the surrounding expression. Addition still finds the sum of the numbers on both sides of the operator, and multiplication still finds the product.
|
||||||
|
|
||||||
|
However, the rules of operator precedence have changed. Rather than evaluating multiplication before addition, the operators have the same precedence, and are evaluated left-to-right regardless of the order in which they appear.
|
||||||
|
|
||||||
|
For example, the steps to evaluate the expression 1 + 2 * 3 + 4 * 5 + 6 are as follows:
|
||||||
|
|
||||||
|
1 + 2 * 3 + 4 * 5 + 6
|
||||||
|
3 * 3 + 4 * 5 + 6
|
||||||
|
9 + 4 * 5 + 6
|
||||||
|
13 * 5 + 6
|
||||||
|
65 + 6
|
||||||
|
71
|
||||||
|
|
||||||
|
Parentheses can override this order; for example, here is what happens if parentheses are added to form 1 + (2 * 3) + (4 * (5 + 6)):
|
||||||
|
|
||||||
|
1 + (2 * 3) + (4 * (5 + 6))
|
||||||
|
1 + 6 + (4 * (5 + 6))
|
||||||
|
7 + (4 * (5 + 6))
|
||||||
|
7 + (4 * 11 )
|
||||||
|
7 + 44
|
||||||
|
51
|
||||||
|
|
||||||
|
Here are a few more examples:
|
||||||
|
|
||||||
|
2 * 3 + (4 * 5) becomes 26.
|
||||||
|
5 + (8 * 3 + 9 + 3 * 4 * 3) becomes 437.
|
||||||
|
5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4)) becomes 12240.
|
||||||
|
((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2 becomes 13632.
|
||||||
|
|
||||||
|
Before you can help with the homework, you need to understand it yourself. Evaluate the expression on each line of the homework; what is the sum of the resulting values?
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
You manage to answer the child's questions and they finish part 1 of their homework, but get stuck when they reach the next section: advanced math.
|
||||||
|
|
||||||
|
Now, addition and multiplication have different precedence levels, but they're not the ones you're familiar with. Instead, addition is evaluated before multiplication.
|
||||||
|
|
||||||
|
For example, the steps to evaluate the expression 1 + 2 * 3 + 4 * 5 + 6 are now as follows:
|
||||||
|
|
||||||
|
1 + 2 * 3 + 4 * 5 + 6
|
||||||
|
3 * 3 + 4 * 5 + 6
|
||||||
|
3 * 7 * 5 + 6
|
||||||
|
3 * 7 * 11
|
||||||
|
21 * 11
|
||||||
|
231
|
||||||
|
|
||||||
|
Here are the other examples from above:
|
||||||
|
|
||||||
|
1 + (2 * 3) + (4 * (5 + 6)) still becomes 51.
|
||||||
|
2 * 3 + (4 * 5) becomes 46.
|
||||||
|
5 + (8 * 3 + 9 + 3 * 4 * 3) becomes 1445.
|
||||||
|
5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4)) becomes 669060.
|
||||||
|
((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2 becomes 23340.
|
||||||
|
|
||||||
|
What do you get if you add up the results of evaluating the homework problems using these new rules?
|
376
www/statics/aoc/2020/18_input.txt
Normal file
376
www/statics/aoc/2020/18_input.txt
Normal file
@ -0,0 +1,376 @@
|
|||||||
|
(3 + 8 * 9 * (4 * 6 + 3 + 4)) * 9 + 9 * 7 * ((9 * 7) + 4)
|
||||||
|
(9 + (9 * 3 + 2 * 2 + 6 * 2) + 7 + 9) + 5
|
||||||
|
8 * 7 * (3 + (2 * 5 + 8)) + 6 + 8 + 6
|
||||||
|
(4 * 6 + 7 + 7 * 4 + 7) * (5 + 6 * 6 * 6 * 8) * 8 * (5 * 4 * 9 + 4 + 3 * 9) * 3
|
||||||
|
(8 + 8 * 2) * 9 * 5 + (2 + 2 + 3 * 7 * 5 + 6) + 5
|
||||||
|
(4 * (2 + 4) + 3 + (7 * 5 * 6 * 5 + 2 + 9)) + 8 * ((6 * 6 + 2 + 7 + 2) * (4 * 9 * 7 * 4 * 7)) + 8 * 2 * 4
|
||||||
|
(5 + 4 + 6) * (6 * 7 + 5 * 9 * 6) * 6 + ((4 + 5 + 3 * 5 + 6) * 6 + 2)
|
||||||
|
(4 * 7) * 2 * (2 * 9 * 6 + 8)
|
||||||
|
7 * (3 * 4 * 5 * 8)
|
||||||
|
(8 * (9 + 5 * 5 + 9 + 5 + 2) * 6) * (4 + 5 * 9 + (7 + 2 + 8) + 5 * 7) + 3
|
||||||
|
(2 * 4 * (3 * 4 * 5) + 5) * 2 + (6 * 4) + ((4 * 4) * 3 + 2 * 6) + 9 * ((7 * 6 * 8 + 2 + 7 + 9) * 7 + 3 * (8 + 7) * 6)
|
||||||
|
6 * 3 * (9 * 2 + 8)
|
||||||
|
2 + (6 * 4) * 7 * 7
|
||||||
|
2 + (9 + (9 + 7 + 3 * 4 + 6 * 7) * 9) * (7 * (5 * 8 + 8 + 6 + 6) * 7)
|
||||||
|
(2 + (5 + 5 + 9 * 4) + 3) * 2 + 2 * 6 * 4
|
||||||
|
5 * 3 * ((8 + 8 + 7 + 3 + 2) + 9)
|
||||||
|
((9 * 4 + 5 + 7) * 8 * 3 * 6 * (7 + 8 + 8 * 7 * 5)) + 5 + 8 * 9
|
||||||
|
(5 * 7 * 5 + (8 * 3 * 9 * 3)) * (8 + 7 + 8) + (2 + (3 * 7 + 4 * 8 + 4 * 3) * 3)
|
||||||
|
7 + 4 * (3 + 9 * 5 + 3 * 3) * (5 * 7 + 5 + 3)
|
||||||
|
(7 * 9 * 3 + (2 * 7 * 4 * 5 + 8 + 8)) * ((9 + 6 * 3) + 8 + (3 + 4) * 6 * 8 * 6) + 6 * 4
|
||||||
|
4 * (3 * 4 + 3 + 4 * 4 + 9) + 5 + 8
|
||||||
|
3 + 7 * (4 * (6 * 9 * 3 * 2 + 5 + 3) + 5) + 4 + 9
|
||||||
|
5 + 6 * 2 * 5 + (9 + 6)
|
||||||
|
4 * (4 * 6) + 7 * (3 * 3 + 6) * 8
|
||||||
|
((8 + 8) + (7 + 4) + 5 * (9 * 2 * 9 * 8) * 5 * (2 + 3 * 3 + 2 * 5)) + 5 * 7 * (4 * 7 + (3 + 3 * 5 * 5 + 5 + 2) + 8 * (2 + 2 + 9 + 6 + 3)) + 2
|
||||||
|
6 + 8 + (3 * (8 * 2 + 3) + 9 * 6 + (7 + 9 + 3 * 6) + (7 * 3 * 7))
|
||||||
|
7 + (5 * 7 * 6 * 3) + 5
|
||||||
|
7 + 5 + (3 + 8 * (6 + 8 * 3))
|
||||||
|
9 + (9 + 2 * 3 + 8 * 7) + 6 + (4 + 2)
|
||||||
|
(4 + 8 * 7 * 9 + 7 + (4 + 7 + 2 * 3)) + (2 + 7) * 6 * 6 * 6 + 9
|
||||||
|
2 + 5 + 8
|
||||||
|
6 + ((4 * 8) * 9 * 2 + 7)
|
||||||
|
6 + 9 + 6 + 4 * 5 + (8 * 9 + 9 + 4 + (5 * 3 + 8 * 7 * 4 * 7) + 5)
|
||||||
|
9 + (8 * 2 * 5 * 5 + 6)
|
||||||
|
(4 * 3 + (2 + 3 * 6 + 2) * (9 + 8 + 2 + 8 * 6 * 2)) + 9 + 3
|
||||||
|
((5 * 9) * (7 + 7) * 8 + 6 + 9 * 3) + (2 + 7 + 7 * 9 + 4)
|
||||||
|
((5 + 5 * 2 + 8 + 2) * (7 + 4 + 5) * (3 + 2 + 5 + 5 + 6) * 2) * 4 * 5 + 9 * 6 * 9
|
||||||
|
8 + (4 + (5 + 9 * 9) + 7) + ((7 * 3) + 7 * (4 + 7 * 5 + 8 + 7 + 9) * 3 * 5 + 3) + 4 * 3 * 4
|
||||||
|
((8 * 5 * 7 + 4) + 5) + 2 + (4 + (7 * 9 + 2 * 9 + 5 + 6) + 3 + 8 * (3 + 9 * 8 + 5 + 6 + 2)) * 7
|
||||||
|
6 * 9 * (3 + 9 + 9) + 7
|
||||||
|
4 + 4
|
||||||
|
(2 + (3 * 8 + 6 * 6 * 8) * 3) + ((3 + 6 + 2 * 6 * 6 + 4) * (7 * 4 + 4 * 9) + 3 + 5 * (7 * 3 * 9 * 4 + 3 + 2)) + 3
|
||||||
|
(2 + (7 * 3 + 4 * 8)) + 5 + 2
|
||||||
|
(3 + (8 + 9 * 2 + 4) * (9 * 7 * 8)) + (3 * 2) * 7 * 5
|
||||||
|
5 + 7 + 3 + ((2 * 9 + 8) + 9) * 7 + 7
|
||||||
|
(4 * 4 * 2 + (2 + 2) * 8 * 2) * 4 + (5 + 6 + 3 * 6 + 2 * 2) * 9 + 6 + 9
|
||||||
|
9 + 9 + ((8 * 5 * 6) * 3 + 2 * 2 + (2 * 4 + 7 + 6 + 7) * 3)
|
||||||
|
((6 * 9 + 6 * 3) * (5 * 7) + 2) + (2 + 6 + 6 + (6 * 3 * 3 * 5 * 5) * 4)
|
||||||
|
2 * 4 + 2 + 3 + 3
|
||||||
|
9 * 2 + 6 * 6 * 4 + 7
|
||||||
|
3 * (4 + (6 * 5 * 7 + 7 + 4) + 6 + 8) * 8 * 3 * 6 * 2
|
||||||
|
5 * (7 + (4 * 3 * 9) * 8 * 6) * 2
|
||||||
|
3 + 6 + (5 + 4) * 7 * 2
|
||||||
|
7 + (6 * 6 * 4) * 9 + 9 + 3
|
||||||
|
9 + ((2 * 5 * 7 * 9 + 2) * (2 + 6 + 7) + 8 * 2 * 9 + 8) * (2 + 2 + 6 * 8 + (8 * 6 + 3 * 6) * 3) * 6 + 8
|
||||||
|
(5 + 2 + 6) * (7 * 7 * 8)
|
||||||
|
(6 * 2 + 9) + 9 * (3 + 9 * 5 + 3)
|
||||||
|
5 + 2 + (6 + (9 + 2 + 5 * 5 * 8 + 5)) + 3 * 2 + (4 + 4 * 2 * 6)
|
||||||
|
6 + 4 * (8 * 5 + 4 * 2) + 8
|
||||||
|
9 * 6 * 6 + 2
|
||||||
|
7 * (6 + 2 + 4 * 5 + 6) * 6 * (6 + (8 + 9 * 9 + 9) * 8) + 8 + (3 + 2)
|
||||||
|
5 * 2 * (4 + 8) + 8 * 3 + (2 + 8 + 8 * 6 * 9)
|
||||||
|
3 + 6 * (8 + (2 + 9 + 5 + 2 * 6) + 3 * 9 * 7 + 2) + 3 + 5
|
||||||
|
(6 + 9 + 5 + 7 * (5 * 5 + 6 * 5) + 3) * 9 + 4
|
||||||
|
4 * (3 * 9 + (9 + 9 + 6 + 7)) * 8 + (2 * 8 + 2 * (2 * 8) * 4 * (4 + 6)) * (4 * 6 * (9 * 5 + 9 * 3 * 6) * 2) + 7
|
||||||
|
4 * 3 + (4 + 8 + 4) * 7 * 3 + 9
|
||||||
|
4 * 8 * 3 * (3 * (9 + 9 * 8 + 3 + 4) + 8 * 6 + 6)
|
||||||
|
2 + 8 * (5 * 4 + 3 + 9) * 2 * 8
|
||||||
|
3 * 8 + 4 * 6 + (5 * 8 * 3 * 8)
|
||||||
|
2 + 7 * (3 + 5 + 2 + 5) * 7 + 9 * 4
|
||||||
|
2 * 4 + 5 * (6 * 7 + 3 * 8 + 4) + (2 * (4 + 6 + 7 + 5 * 2 * 2) + (6 * 4 * 4 + 3 + 7) + 6 + 8)
|
||||||
|
3 + ((6 + 9 + 7) * (2 + 3) * 6) * 2 * (3 * 3 + (9 * 2 + 8) * 7) * 4 + 7
|
||||||
|
8 * (2 + 9) * (6 + (3 * 5 + 7 * 8 + 5 + 9) * 6 * 9) * 6
|
||||||
|
6 + 9 * 8 * 5 + (8 + 5 + 7 * (6 * 6 * 5) * 5 * 7) + (4 + 6 * 2 * 9 * 5)
|
||||||
|
2 * 8 + 3 * 4 * (2 * 8 + 7 + (6 + 9 * 7 + 2 * 9)) * 2
|
||||||
|
5 * (9 + (9 * 6 * 2 + 2) + 6 * 6) + (5 * 4) * 7 * 6
|
||||||
|
((9 + 8 * 7 * 4 * 2) + 3 + 3 * 5) * 8 + 5 + 9 * 4 * 5
|
||||||
|
9 + ((9 + 9) + 4 + 4 + 3 + 6 + (3 + 6)) + 6 * 9 + ((6 + 2 + 3) * 4)
|
||||||
|
6 + ((3 * 5 * 4 + 6) + 6 * 5 + 4 * 9 + (3 + 9 * 2))
|
||||||
|
3 + 3 + (7 + 8) + 8 * (4 * 9 + 8 * 9 + 9 * 9)
|
||||||
|
(5 * 9 * 7 * 4) + 6 + 3 * 5
|
||||||
|
(7 * 8 * 3 + 4 + (8 + 7) * 4) * 2 + 8 + 5 + 4 * 4
|
||||||
|
9 + (8 * 6 + 2 * (8 * 6 + 4 + 2 * 5 + 2) + 4)
|
||||||
|
(7 + 5 + (2 + 4 + 6)) + 9 + 5
|
||||||
|
(4 + 2 * 5 * 6 + 3) * 2 + 2
|
||||||
|
((7 * 8 * 8 + 8 + 5 * 6) * 6 * 8) * 5 * 4 * (7 + 3 * (8 + 6 + 5 + 8) * 8 + 9) * 3 * 9
|
||||||
|
3 + 9 * 8 * (7 + 8) + (9 + 6 + 5 + (8 + 4 + 6 * 5 * 9 * 7))
|
||||||
|
5 + 2 + 6
|
||||||
|
(9 + 2 * 7 + (9 + 3 + 6 * 7) * (9 + 3 * 4)) + 8 * 6 + ((3 * 6 + 8 * 6) + 4 * 4 * 8) + 6 * 6
|
||||||
|
3 + 7 * (8 + 7 * (7 * 2 + 6 + 4 + 3 * 9) + 8 * 7) * ((4 + 7) + 8 + 9 + 5) * 3 + ((2 * 8 + 2 * 3) + 3 + 8)
|
||||||
|
8 + 5 * 9 * (5 + 3 * 4 * 8 * 8) * 7 + (2 + 9 * 4 + 4 + 3 + 8)
|
||||||
|
6 + (9 + 4) + 4 + ((7 + 8 * 3 * 6) * 2 + 6 + 9 * 6) + ((2 + 2 + 3 + 3 + 5) * 5 + 5 + 8 + 7 + 4)
|
||||||
|
(4 + 6 + 7 + (7 * 4 + 7 + 2 + 2)) + 4 * ((9 * 9 + 8) + 3 * 3) + 4
|
||||||
|
5 * (4 + (6 * 9) * 2 + 5 * 8)
|
||||||
|
(7 * 5 + (6 + 2 * 3 + 3 + 2 + 7) * 6 + 5 + 8) + 3 + 5
|
||||||
|
(6 + 4 * 8 + 8 * (7 + 4 + 3 + 9 + 3)) * 5 + (3 + 7 + 4 + (2 + 6 + 5 * 2 + 2) + 7) * 8 + 4
|
||||||
|
8 * ((5 * 9 * 7 * 6) * 5 + 3) * 9 * (6 * 6 * 8 * 2)
|
||||||
|
((4 * 4) + 2) * 5 + 8
|
||||||
|
6 * (4 + (8 + 7 + 8 + 6)) + (9 + 5 * 5 * 6 + 9)
|
||||||
|
((5 + 9 * 6 * 7 + 7 * 3) + 8 + 2 * 8 + 9 * 5) * 2 * 9 * 4 * 6
|
||||||
|
(7 * 5 * 9 + 4) * 3 + 5
|
||||||
|
(5 + 5) + 8 * 9 + 2 * 8 + (7 + 4)
|
||||||
|
8 + (4 * 7 * (7 + 5 * 3 + 7) * 9) * 8
|
||||||
|
2 * (7 * 8 + (7 + 5 + 9 + 8)) * 9 + 9 + 9
|
||||||
|
9 + 8 + (2 + 6 * (9 * 2 * 7 * 7) + 5 + 2 * 5) + 4 + 5
|
||||||
|
(9 + 3 * 4 + 2 * 9) + (7 + 4 + 9)
|
||||||
|
2 * (5 * 5 * 6 * (5 * 6 + 2 + 9 + 5 * 3)) * ((2 * 5 * 6 + 5 + 8) + 8 * 2 + 7 * 9 * 2) + 7 * 2
|
||||||
|
9 * 2 + 7 + 3 + ((9 * 9 * 3 + 7 * 2) + 2 * 2 * (5 * 8 * 3 + 2 * 9 + 6) * 3)
|
||||||
|
4 + (4 * 9 * 2 + 9 + 9 + 2) + 6 * 2 * (7 + 9)
|
||||||
|
2 + 4 + (5 * 9 * 4 + (2 * 4 * 2) * (5 + 8 + 5 * 8 * 4 + 6) + 2) + 9 + 6
|
||||||
|
(7 + 9 * 7 + 8 + 3) * 7 * 6 + (2 + 9 * 7 + 5 * 5) + 2 * ((4 + 3 * 5 + 8) + 7 * 3 * 6 * 9 * 6)
|
||||||
|
(4 * 8 + 8 * 2) + 5 + (5 * 7 + 6 + 2 + 7 + 2) + 3
|
||||||
|
9 * (5 * (2 + 3 + 4 * 3)) * 5 + 9 + 9 * 9
|
||||||
|
9 * 5
|
||||||
|
5 + (9 * 6)
|
||||||
|
7 + 7
|
||||||
|
3 * 4 + 3 + (7 + 3 + 4 + 8 * 4)
|
||||||
|
8 * (5 + 3 + 3 + 2 * (4 + 6)) + (8 + 5 * 9) * 6
|
||||||
|
5 + (2 + (6 * 2)) + 5 + 8 * 9 * 3
|
||||||
|
(9 * 4 * 6 * (4 + 8 * 5) * 5 + 6) + 2 * 8 + 6 * (3 * (6 * 2 * 9 * 4 * 2 * 8) + 9 + (8 * 9 + 3 * 4 + 3 + 8) + 4 + 7)
|
||||||
|
8 * (5 * 8) + (7 + 7 * 5 * 6 * 3 * 4) + (4 * 7) * (3 * 6 + 9 * 4 * 2)
|
||||||
|
2 + (8 + 7 * 2 * (6 * 4 + 9 + 7 * 8) + 2) + 4 * 4
|
||||||
|
2 * (7 + 3 + 2 + (9 + 4 + 8 + 9)) * 2
|
||||||
|
9 * 8 + ((9 * 8) + 8 + 9 * 3 * 6 + 8) + 5 * 6 + (7 + (3 + 5 + 8 + 7) + 2 * (7 * 5 + 5 * 7) * (8 + 3 + 8) * 4)
|
||||||
|
2 + 5 + 4 * (6 * 2 * (8 + 8 + 7) + 3 * 9 * 9)
|
||||||
|
(5 * 5) + 4 * 9 + 8 * 8
|
||||||
|
((4 + 5 * 4 + 2) + (2 * 9)) * (2 + 4 + 3 * 9) * 9 + ((2 + 7) + 9 * (3 + 6 + 2 + 3) * (7 * 8 + 5 * 6) * 9) * 8 * 6
|
||||||
|
2 * 9 * (8 * 6 + 6) + 4 * (5 * 8 * 6 * 4)
|
||||||
|
6 * 7 * 2 * 3 + (8 + 8) * 6
|
||||||
|
(5 * 7) + 3
|
||||||
|
8 * 2 * (8 + 8)
|
||||||
|
5 * 7 + (6 + 4 * 3) + 3 + 9
|
||||||
|
6 * 2 * 6 * 2 + 8 * 4
|
||||||
|
(2 * 8 + 9 * 6 * (7 + 3 + 4 * 4 + 4 * 9)) + 2 + (6 + 3 * 5 + 4 + 9 + 8) + (3 * 7 + 3 * 2 + 6)
|
||||||
|
((3 * 8 * 8 * 4 + 6 * 6) * 7) * 6
|
||||||
|
(2 + 6 * 2 * 8 * (2 + 6 + 5 * 6) * 4) + 9 * 2 + 7
|
||||||
|
3 + 4 * 4 + 8
|
||||||
|
((8 * 6 * 8 + 7) * 8 * 7) * 4 + ((5 + 3 * 9 + 2 + 3 * 4) + 2 + 6 + 4 + (4 + 3 + 2)) * 7
|
||||||
|
((6 * 9 * 4 + 5) * 5) * 7 * 3 * 7
|
||||||
|
2 * 5 + 8 * ((6 + 5 * 6 * 5 * 3 * 2) * (7 * 7) * (8 * 3 * 3 * 3 * 8) * (6 + 8 * 9 + 9 * 4)) * 5 * 6
|
||||||
|
6 * ((6 * 7) + 9)
|
||||||
|
8 + 2 + 5 * 3 * ((4 + 3 + 8) + 7 + 5 * 6 * (2 * 6 * 2)) * 9
|
||||||
|
(5 * 5 + (2 * 9 + 8) + 8 * 8 * (3 * 6)) * 9 * 3 * 2
|
||||||
|
(9 * 8 * 7) * 7 + 7 * 4 + 8 * 7
|
||||||
|
((3 + 8 + 2 * 7) + 3 + 7 * 2) + 4 + 3
|
||||||
|
6 * 5 + 3 + (4 + 6 * 2 + (2 * 7)) + 2 * 2
|
||||||
|
7 * (4 * 9 + 3 + 4 * 2 * 5) * 9 + 7 * (9 + 6 * 7 * 8) * 3
|
||||||
|
((2 + 2) + 8 * 7 + (5 + 6 * 7 * 9 * 3) + 6 + 4) * 9
|
||||||
|
((6 * 5 * 2 * 4) * 6 * 6 + 2 + 7 + 6) + 2
|
||||||
|
7 * 4 + 3 * 3 * 9
|
||||||
|
5 * ((3 + 9 * 2) * 6 * 3 * (5 * 3) * 6 + 6) * 4
|
||||||
|
(3 * 7 * 9 + 9 * 6) * 5
|
||||||
|
6 + (8 + 5 * 3 * (7 * 6 + 5 + 4 * 7 + 8))
|
||||||
|
4 * 2 * 4 * (7 + 8 * (7 * 5 + 3 * 3))
|
||||||
|
((5 + 9 + 4 * 2) * 2 * (7 * 3 + 7 + 3 * 8 + 6) + 9 + (2 + 6 + 7 * 2 * 9) * 8) + 7 * (4 + 4)
|
||||||
|
9 + (7 * (8 * 2 + 5 * 8 + 7) * 7 + 6 + 6 * 2) * 2
|
||||||
|
(2 * 4) + 6 + (8 * 7 + 8 * 2 + (5 * 7 + 9 + 8 * 8))
|
||||||
|
3 + (3 + 2 * (5 * 4)) * 2 + (4 + 2 + 6 * (4 + 7 + 2)) * 3
|
||||||
|
(9 * 6 + 9) + (9 * 8 * (4 * 6 + 5 * 6 * 4)) + 3 + 2 * (9 + 3 + 5 + 5 + (4 + 8 + 8 + 2 * 5))
|
||||||
|
(8 + 7 * 3 + 2 * 5 * 4) * 4 * 9 + (2 + 5)
|
||||||
|
6 * 5 + 6 * 9 + 2
|
||||||
|
(3 * 3 + 5 * 6) + 2 * 5 * 3 + 8 * 7
|
||||||
|
(8 + 9) * 5 * 7
|
||||||
|
7 + (2 * 8 + (6 + 5 + 2 + 3 * 8 + 3)) * 8 * 3 * 4
|
||||||
|
(6 + 9 * 2 * 2 + 4 * 7) + 2 * (9 + 9 + 8 + 9 + 7) + (2 + 5 * 6 * 3 + 3 + 3)
|
||||||
|
3 + 3 + ((2 + 2 + 9 * 8 * 9) + 4 * 8 + 6 + 8 + 6) * 9 * (4 + (8 * 8 + 5 * 9 * 9 * 9) + (3 + 4) + 6 + 9) * 7
|
||||||
|
9 + (3 + (4 + 6 + 9 * 2 * 7 * 4) * 9) + 9
|
||||||
|
7 + (4 + 8) * 2 * 9 * 9
|
||||||
|
6 + (9 * (5 * 4 * 3 * 5) * 4)
|
||||||
|
3 * 8 + 4 + 2 + 5 * (4 * (8 * 6 + 2 * 5 + 8 * 4))
|
||||||
|
(4 + 9 * 3) * 2
|
||||||
|
5 + 3 * ((9 + 6) * 5 * (3 + 8 + 4))
|
||||||
|
((9 + 5 * 2 + 9) + 7 + 6 + 9 * (3 + 9 + 6)) + 4 + (3 + (9 * 3 + 7 * 9) * 6 + 9 + 9)
|
||||||
|
(9 + 6 + 6) + 3 + ((6 + 5) * 6 + 9 * 7) * (8 * (5 * 5 * 3 + 8 + 5 * 4) + (7 + 8 + 3 * 2 * 3 * 8) * 8 + 8) * (7 * (8 + 6 + 9 + 8) + 4 + 3 * 6) * 3
|
||||||
|
6 + 2 + 4 * (5 + 6 * 6) + 6 + 5
|
||||||
|
(2 * 7 + 5 + (4 * 4 + 8 * 5) * 4) * 6 * (4 + 2 * 2 * 3)
|
||||||
|
9 + (8 * 8 * 8 * 2) + 8 * 5 + 5 + (3 + 6 + 4 + 6 + 6)
|
||||||
|
(3 * (2 * 5) * 6 * 9 * 9 * (7 + 5 + 3)) + 6 + (4 + 2 * 9) * (2 * 6 + 7 + 6 + 3) + 4
|
||||||
|
3 + 7 + 6 * 6 * (4 * (6 * 6)) + 5
|
||||||
|
(7 + 2) + 4 * 3 * (5 + 9 + 6)
|
||||||
|
4 * 7 * (6 * 8 * 3 * 6 + 5) + (8 * 8 * 4 + 5) * 4
|
||||||
|
9 * 3 * 8 + 7
|
||||||
|
3 + 7 + 3 + (6 * (2 * 2 + 7 * 4)) + 8
|
||||||
|
5 * 6 * (7 * 9 * (4 + 8) + (5 * 3 + 7 * 4 * 7))
|
||||||
|
3 + 4 + 2 + ((6 + 5 * 7 * 8) * 9 * 8 * 8)
|
||||||
|
(5 + 5 * 2) * 6 + 3 * (4 * 5 + 5 * 5 * 2) + 4
|
||||||
|
(4 + 4 + 9 * 7 * 9) * 3 + (3 * 4) + 5 * 6 + 7
|
||||||
|
6 * (4 * 5 + 6 * 3 + 3 * 3) * 8 + 2 * 8
|
||||||
|
3 * (3 * (4 + 3 * 2 * 5) * (2 + 4 * 5 + 8) * 5 + 3 * 8) * 6
|
||||||
|
6 + (2 * 3 * 7 * 8 + 7) * 4
|
||||||
|
4 * 9 * (7 + 6 + 5 * 6 * (8 * 9) + 9) + 8 * (9 * 2 + 9) + 6
|
||||||
|
9 * 5 + 4 * ((3 + 6 * 4 + 4) + 8 + 4 + (7 + 4 * 3 + 7 * 5 + 9))
|
||||||
|
3 + ((9 * 4 * 6 + 4) * 4 * (7 + 3 + 8 + 7 + 3 * 4)) + 7 * 4 + 5 * 6
|
||||||
|
(8 + 2) * ((4 + 8 * 8) * 8) * 5
|
||||||
|
2 + 8 * 8 + (5 * 7 + 3 * 4) * 4 + 4
|
||||||
|
5 * 5 + 3 * 8 + ((7 + 5) * 3)
|
||||||
|
(5 + 8) * (4 * 3 * 9 * 8) * 7
|
||||||
|
(3 + 4 * (5 + 4) + 7) + (7 * 9 * 3) + 2 * 4
|
||||||
|
2 * 3 * ((6 * 2 + 8 + 2 * 9 + 5) * 3 * (4 + 4 * 3 + 2) + 8 * (7 * 3 * 5 * 9 + 3) * 8)
|
||||||
|
3 * 4 * (7 * 4 + 5 + 8 * 5) + ((9 * 5 * 5) + 4 + (6 * 6 + 8 * 2 + 9) * 2) + (3 + 4 + 7 * 7 + 9 * 5)
|
||||||
|
6 * 2 + 8 * 4 * (9 * 4 + (5 * 3 + 8) + 3 + 9) + 2
|
||||||
|
5 + (9 * 4 + 4) + (5 * 8 * 6 + 7 + 2 + 2) * 3 + (3 * (4 * 4 + 6) + 4)
|
||||||
|
5 + 8 * (5 * 7 * 8 * 4 + 6)
|
||||||
|
8 * 3 + 4
|
||||||
|
6 + 2 + 5 + 4 * (9 + 2 * 9) + 5
|
||||||
|
5 + 2 + 6 * (4 * (8 + 7 * 6 * 7) + (4 * 4 + 7) + (2 * 3 + 3 * 4 + 6 + 3) * 4 + 4) * 3
|
||||||
|
((5 * 4 * 2 * 4 + 9) * 4 + 3 + 4 * 7 + 8) * 3 * 6 + 4 * 2
|
||||||
|
(9 + 7) * 7 * 7 * ((6 * 3 * 4 * 8) + 9) + (7 + 4 * (3 * 3 + 6 * 2 + 7) * 9)
|
||||||
|
9 * (7 * 4 + 9) * (8 * 2 * 5 * 7 * (8 * 3 + 9 + 3 * 4) + 6) * 2 * 3 + 3
|
||||||
|
8 + ((3 * 5 + 3) + 5 * 7 * 8 * 8) + 3
|
||||||
|
((9 + 3 * 5 + 2) * 6) + 9 * (5 * 5) * 6
|
||||||
|
5 + (5 * (5 * 8) * 9 + 2) * (8 + (7 + 4 + 9 * 6 * 6 + 8)) * (4 + 8 * (6 + 6) + 7) * 3
|
||||||
|
5 * (2 + (6 + 9 * 4) + 4 * (8 * 2 + 7) * 8 * 2) * 6 * (7 + (6 + 8 * 6 * 8) * 6)
|
||||||
|
(7 * 7 * 5 + 8 + 2 + 3) * 3
|
||||||
|
5 + 3 + 3 + (6 + (3 + 7)) * (4 + 6 + 9) * 8
|
||||||
|
4 + 3 * (9 + (5 * 8 * 8 * 5 + 3) + 4 + 2 + 9)
|
||||||
|
2 + 7 + 5 * 6 + ((4 * 6 * 9 * 2 + 2 + 5) * (7 + 2 * 4 * 7 + 8) + 8)
|
||||||
|
(9 + 7 * 8 * (6 * 5 + 7 * 3)) + 4 * 7 + 5 * 9 + 9
|
||||||
|
((7 * 7 + 7 + 2) + 9 + 5 + (8 + 6 * 3 * 6 + 9) * (6 * 2 + 4 * 7) * 9) + 6
|
||||||
|
(3 + (3 * 4 * 6 + 4)) * 7
|
||||||
|
(6 * 2 * (5 + 5 + 4 + 7 + 8)) * 6 + 4 * 4
|
||||||
|
4 * 8 + (5 + 8) + 3
|
||||||
|
3 + 8 + 3 * (9 + (5 * 4 * 9) * 5) * (8 + (6 * 7 * 3 + 7 * 6) * 2) * 8
|
||||||
|
3 + 8 * (2 * 8 * 5 + 2) + 2 * ((8 + 7 * 6 + 5 + 2) * 6 * 3 * 3 * 5) * (7 * (5 + 5 + 3 * 6 * 3) * (5 * 4 + 4 * 9 + 4) + (9 + 9 + 9 * 5) + 7 * 3)
|
||||||
|
5 + (9 + 5 + 9 + 7 + (3 + 4 + 3 * 8)) * 8
|
||||||
|
4 * (9 + 4) + 4 + 3 + 6 + 9
|
||||||
|
((5 * 4 * 8 * 8 + 8 + 7) + 4) + (5 * 8 + 2) * (8 * 7 * 4 + 9 * 4 + (4 * 2 * 7 + 6)) + 3 + 6
|
||||||
|
5 * (8 + (9 * 9 * 5 * 2 + 8 + 4) * 6 + 6) + (7 * 5 * 7 * (9 * 2 * 8 + 5 * 7) * (5 + 4 + 2 * 8 * 8 * 9) * 4) + 6 + 9
|
||||||
|
((4 * 4 * 8) + 8) * 7 * 3 + 8 * 7
|
||||||
|
5 + 4 * 2 + 8 * (7 + 2 + 9 * 2) + 4
|
||||||
|
5 * (4 + 9 + (3 * 4 * 5) * 9)
|
||||||
|
4 + 2 + 3 * 3 + 9 * (9 + 4 * 9)
|
||||||
|
5 * 4 + 3 * 8
|
||||||
|
(8 + 4 * 6) * (8 * 3 + 4 * 8 * 9 * 2)
|
||||||
|
(9 + (8 + 4)) * 6
|
||||||
|
(9 + 5 * 5 * 8 + 7 * (9 * 6 * 6)) + 2 + 4 * 2 * (3 * 8 * (5 * 5 + 5 * 7) + 8 + (3 + 7 * 5 + 4 * 5) + 5) + 9
|
||||||
|
3 * 9 + 2 * (7 + 8 + (9 * 6 + 4) * (4 + 8 * 9 + 2 + 3) + 3)
|
||||||
|
(4 + 7) * 3 + 7 * 5
|
||||||
|
6 * (4 * 5 + (2 + 7 * 8 + 9 + 5) * 7 + 9 * 2) + 8
|
||||||
|
8 * (8 * 3 * (3 * 3 + 2) + 9) * 5 + (7 * 3 * 2 * 4)
|
||||||
|
9 + 3 + 4 * (8 + 4 * (2 * 8 * 3) * (5 * 4) * 7 + 5) * 8
|
||||||
|
8 * 9 + 6 * (3 * (6 * 8 * 6) + 7 + 9 * 5 * 7) * (7 * 3 + 3 * 6 * 8)
|
||||||
|
8 + (8 * 6 + 7 + 2 * (4 * 6 * 3))
|
||||||
|
4 + 2 * 7 * ((7 + 6 + 7) * 8 * 6) * (2 * 7 * (2 + 4 + 9 + 2) * (4 + 3 + 6 + 2 + 6) + 6 + 7)
|
||||||
|
(3 + 9) * 7 + 5 * (3 + 3 * 2 * 6) * 3 * 2
|
||||||
|
(5 * (8 * 3 + 6 + 5 * 9) * 8 * 6 + 9 * 9) + 8 + 5
|
||||||
|
8 + ((9 + 3 + 2) * (7 + 9 * 6 * 3) + (4 + 6 * 5 + 8 + 3) * (6 + 9)) + 9 * 7 * 7
|
||||||
|
2 + 9 * 3 * ((6 + 3 + 3 + 6 * 7 + 9) + 8 + (5 * 5) * (4 * 8 * 5) * 3)
|
||||||
|
8 + 6 + 4 * 2 * ((5 * 8 + 9 * 2 * 3) * 3 * 9 + 4 * 9 + (3 + 5 * 9)) + 2
|
||||||
|
7 * ((6 + 8 + 5) + 9) * 4 + 4
|
||||||
|
9 + 3 * 4 * (6 + (9 * 3 + 7 * 3 + 7 + 3)) * (4 * (4 * 3 + 4))
|
||||||
|
7 * (5 + 7 * 5) + 2 + ((7 + 6 * 7 * 9) + 5 + 3 + 9 + 6) * (7 + 4) * 2
|
||||||
|
2 + 4 * 5 + 6 * 3
|
||||||
|
2 * 9 * ((9 * 5 * 8) + (8 + 3 * 8)) + (7 * 8)
|
||||||
|
7 * 6 + 5 + (5 * 4) + 9 * 2
|
||||||
|
4 * 5 + 2 + (4 * 4 * 7) + 4
|
||||||
|
5 + 5 + 2 * (8 * (3 + 5 + 9 + 4) + 7) * 3
|
||||||
|
3 + ((2 * 8 + 7 * 3 * 3 * 4) * 3 + 9) + ((6 * 9 * 4) + 4) * 8 * 6
|
||||||
|
((2 * 5 + 4) * 2 + (3 + 4) * 8) * 7 * 9 + 2 + (9 * 7 * 8 + 5 + 9) + 8
|
||||||
|
7 * (9 * (5 * 3 * 2) * 7 * 5 + 3 + 7) + 7 * 9 * 3 + 6
|
||||||
|
((3 * 3) * 7 + 9 * 7) * 6 * 8 + (4 * 3 + (7 + 4 * 2) * (5 * 9 * 6 + 4 + 6 + 4)) * 2
|
||||||
|
3 * 6 * 2 + ((4 * 9 + 7) + 6) * 3
|
||||||
|
9 * (3 + 8) * 6 * 3 * 7 * (4 * 3 + 7 * 2 + (8 + 7 * 6 * 2 * 8 + 3) * 3)
|
||||||
|
((5 * 4 * 5 * 6) * 8 * 8) + 8
|
||||||
|
((2 * 9 + 2 + 6 * 5) * 4 * 2 * (4 + 4 * 9 + 3 * 2 * 8)) * 4 * 7 * 3 + 4 + 7
|
||||||
|
6 * 3 + 5 * 4 + 8 + 9
|
||||||
|
8 * 2 + (7 + (6 + 4) * (6 * 5) * 3 * 7 * 8) * 2 * 9 + 5
|
||||||
|
6 + (3 * 2 * 9 * 8 * 5) * 2 + 6 + ((6 * 8 * 7 + 5 * 9) + 3 * 3) * 5
|
||||||
|
(8 + 3) + 3 * (3 * 3 * 7) + 8 * 8 + 3
|
||||||
|
6 + 2 * (2 + 2 + 9 * 2)
|
||||||
|
(7 * 2 * 6 * 3 * 4 + (7 + 6 + 6 + 3 + 2 * 7)) * 8
|
||||||
|
(7 + 2 + 2 + (9 + 8) + 3) + (4 + (5 + 7 * 6 * 2) + 7 + 9 + (2 * 8 * 4 * 3 + 6)) * (6 * (9 * 6 + 4 + 7) + 8) * 6 + 2 * 6
|
||||||
|
6 + 5
|
||||||
|
(9 * (6 * 9 * 2 + 3 + 5) + 7 + 2 + 4) + 8 * (6 + 5 * 9)
|
||||||
|
8 * (5 * 8) + 5
|
||||||
|
9 * 2 * 9 * 9 + 7
|
||||||
|
(8 + 9 + (8 + 7 * 4 + 4) + 4 + 2) + 6 * ((9 + 4 * 9 * 3 + 5 + 2) * 8 * 3 * 8 * 3) + 8
|
||||||
|
5 + (8 * 4 * 5)
|
||||||
|
(3 * 7 * 4) + 6 * 8 * (5 + 4 + 8 + 5) * (4 + 8 + 9 * 8 + 7 * 7) + (4 * 8 + (5 + 4 + 2 * 2))
|
||||||
|
9 + 6 * 7 + 2 * (9 * (3 + 2 + 7 * 9) * 3 * 4 * (6 * 6 * 9 + 4)) + 9
|
||||||
|
7 + (8 * (5 + 7 * 6) * 8 + (2 * 4 + 5 * 4 + 6 * 7) + 3) + 9
|
||||||
|
5 + 7 * (3 + 8 + 2 * 8 * 5 + 4) * 7 * 8 + 8
|
||||||
|
9 * 4 * 4
|
||||||
|
(9 * 3) * ((5 * 7) * 8 * 2 + 4) + 5 + 9 * 3 + 5
|
||||||
|
((2 * 5) + 2 + (7 * 5 * 9) * 2 + 5) + 7 + (5 + 2 + (8 + 4 * 4 + 6))
|
||||||
|
((5 + 4 + 9) * 4 * 4 * 6) * 4 * 6 + 5
|
||||||
|
4 * 8 + 3 * ((8 + 8) * 5 * 7 + 9)
|
||||||
|
8 * 6 + 5 + (5 * 9 + 5 * 7 * (9 + 8 * 7) * 5)
|
||||||
|
7 * (3 + 4 * (3 + 6) + 6 + (3 * 8) * 9) + ((8 * 5 + 3 * 8) + 2 + 3) + (9 + 6 * (6 + 8 + 6 * 8 + 8 + 6)) * 2 * 7
|
||||||
|
8 + ((6 + 6 + 5 + 3 * 3) * 5 * 8 + 9) + 2
|
||||||
|
((9 + 8 * 8) * 8 + (6 + 2 + 7 + 3 * 3 + 6) + 2) * ((2 + 3 * 7 + 6) + 3 * 7 + 8 + 6 * 6) * 3 * 8 + 9
|
||||||
|
5 + (8 * (4 * 2) * 2 + 9) * 2 * 6
|
||||||
|
(4 + 4 * 9) + (6 + 5 * (4 + 2 * 2 * 4 * 8) * 2 + 4)
|
||||||
|
6 + 7 + 5 + (6 * (2 + 6 * 2 + 5 + 9)) * 6
|
||||||
|
5 * 3 + 2 + 2 * ((7 + 6 * 8 + 6 * 7 + 5) * 4)
|
||||||
|
6 * (7 * 8) * (6 + 6 + 2 + 4 + 6 + 6)
|
||||||
|
((7 + 3 * 7 * 4) + 7 + 9 * 4) + 4 * (2 * 9 * 7 + (3 + 9 * 3)) + 8 * 9
|
||||||
|
2 * 3 * 2 * 5 + 9 * 6
|
||||||
|
((3 * 7 * 9 + 4 + 5 + 3) * 8 + (4 + 5 + 8 + 3) + 2 * 2) * 7 * 5
|
||||||
|
3 + ((8 * 2) + 8 * 4 + 2) * 4 + 9 * 5 + 5
|
||||||
|
3 + 9 + (6 * 9 * 8) * ((8 * 3 + 9) * 4 + 5 * 7 + 6) + 7
|
||||||
|
9 + (8 * 4 + 2 * 6 * 4 * 4) * 9
|
||||||
|
5 + 3 + 5 * 3 + 4 * 3
|
||||||
|
(5 * 3 * 4) + 7 + 8 + 6 + 5
|
||||||
|
(6 * (9 * 7 + 5) + 7 * 4) * 2 * 9 + (7 + 5 * 4 + 7 + 3 * 6)
|
||||||
|
6 * 9 + 2 * 2 + (6 + (6 * 6 + 2 * 4 + 8) + 7 * 5)
|
||||||
|
((5 * 9 + 3 * 6) + (5 + 2 + 3 * 4) + 3 + 8) * (9 * 2 + 7 * (8 * 5)) * 6 * 2 + 5
|
||||||
|
(9 + (5 + 7 + 2 * 9) * 4 * 2) * 5 * 5 + 7 + 7 + 9
|
||||||
|
9 + 7 + 4 + (9 * 7 + 2 * (5 + 4 + 3 * 4))
|
||||||
|
6 + (3 + 5 * 4 * 8 + (7 + 4 * 3 * 4)) * 7 * 4
|
||||||
|
9 * ((7 + 6 * 3 * 6) * 7 + (4 * 5 * 3)) + 9 + (7 * 6 + 8 * 5) + 9
|
||||||
|
4 + 7 * 6 + 6 + (7 + (7 + 8 * 7 + 8 * 4 * 9) + 3 * 9) + 7
|
||||||
|
(9 + 7 + 2) * 3 + (7 * 8 + 9)
|
||||||
|
2 + 4 * (2 * 8 + (7 + 5) * 6) + 4 + 4 + (3 + 2)
|
||||||
|
(5 + (2 * 4 + 9 * 6) * 9 + 3 * 7 * 3) + (5 + (2 * 4 + 7 + 6) * 4 + 3 + 2) * (7 + 9 + (6 * 9 + 6 * 9) + (2 * 2 + 5 + 5) * 4 + 7)
|
||||||
|
(8 * 6 * 8 * 7 + 7 + 6) + 8 + 9
|
||||||
|
6 + (3 * 4 + 6) + 9
|
||||||
|
5 * 2 * 6 + 2 + (4 * 8 * 2 + (4 + 7 + 3 * 8 + 2)) * (4 + 8)
|
||||||
|
(4 + 2 + 7) + (7 * 2 * 3 * 8)
|
||||||
|
(9 * 6 * 2 * 9 * 7) * 4 + 4 * 4 + 4 * 8
|
||||||
|
9 * 3 * (9 + (5 + 3 + 2 + 6)) + (8 * 6 * 4) * 8
|
||||||
|
8 + (6 + 3 * 6) * 2 * 8
|
||||||
|
5 * 4 * 3 + (9 * 8 + 6)
|
||||||
|
(2 + 4 * 8 * 9 * 9 * 2) + 7 + 7 + 3 * 8
|
||||||
|
(2 * (4 + 7 + 8 * 4) * 4 * 6 * 7 + 4) * 6 + 5 * (6 + 4 * (6 + 9 * 2 + 2) + 2 + 5) * 4 * 5
|
||||||
|
(9 + 4 * 8 * 8) * 8 * (6 + (8 * 5) * (2 * 7 * 4 + 4 * 6) + 3 + 4 + 9) + 9 * 9 + 4
|
||||||
|
(7 * 4 + 3) + 4 + 7 * 9 * 7 + (6 * 3)
|
||||||
|
4 * 2 + 8 + (3 * 2 * (4 * 8) + 3)
|
||||||
|
6 + 6 * 3 + (9 * 5 * 5 + 4 + 9 * 9) * 3
|
||||||
|
2 + 8 * (2 + 8 + 2) + (8 * 6 * (3 * 6 * 4 + 8 * 6 * 6) + (3 + 5 + 7 * 8)) * 9 * (4 * 9 * 5 * 6 * 5 * 7)
|
||||||
|
4 + ((8 + 9 * 5 * 6) + 3 + 9)
|
||||||
|
(5 + 5 + 5 * 6 * (6 * 5)) * 7 * 2
|
||||||
|
4 + 6 + (7 * 2 * (9 * 7 * 5 + 5) + 4 * 2) + 9 * 9 * 2
|
||||||
|
6 + 9 * 8 * 3 + 9 * (3 * (3 * 2 + 2 + 9 + 7) * 2 + 2 + 3 * 8)
|
||||||
|
8 * 6 * (9 + 7 * (8 * 9 + 7)) + 8 * (3 + 3 + (4 * 2) + 4 * 7 + 4) * 4
|
||||||
|
9 * 2 + 2 * 4
|
||||||
|
(6 + (6 + 9 + 3 + 5 + 6)) * 8 + 8 + 3 * 8 * 9
|
||||||
|
(8 + 2) + 3 * ((2 + 2 * 5 * 2 + 9 + 6) * 6 * 6 + 3 + 3 + (5 + 9 + 7 + 5 + 9)) * 2 * ((4 * 7 + 4) * 6)
|
||||||
|
(4 + 8 * (9 + 8) + 2 + 4 * 2) + (7 + 5 + 3 + 9 * 4)
|
||||||
|
8 * 5 + 8 + (7 + 2 + 8 + 7 + 8) * (9 * 7)
|
||||||
|
7 + (9 * (9 * 4 * 8)) + (8 + 8 * (2 + 6 + 2 + 6) + (7 * 9 * 2 + 3 + 8 + 7)) * ((5 + 4) + 6 + 3) * 2 + 7
|
||||||
|
6 + ((4 + 2 * 5) + 3 * 7) * 2 + (4 + 9) * 3 + 3
|
||||||
|
9 * 4 + 7
|
||||||
|
((5 + 6 + 6 * 3 * 5 * 8) + 8 + 4) * 6 * 5 * 4
|
||||||
|
6 + ((4 + 7 * 6 * 4) + 8 * 2 + 6)
|
||||||
|
7 + 4 * 8 * 8 * 3 * (7 * 6 + 6 + (8 * 6 * 9))
|
||||||
|
((8 * 5 + 7 + 3 + 7) + 3 + 7 * (4 + 2 * 9)) + (7 * 6 + 2 + 5 + 6) + 2 * 6
|
||||||
|
(9 + 4) + 2 + 8 * (6 + (7 + 8 * 9 + 6 * 8) + 6) + 3
|
||||||
|
6 + (6 * 7 + 3 * 7 * (2 + 2 * 2 * 2) * 8) * (2 * 6 * 7 + 4 * (9 + 9 * 3 + 4) + 4) * 6
|
||||||
|
(6 + 9 + 6 + 8 * 5) * 8 * ((4 * 9 + 2 + 7 * 6 + 4) + (7 + 2 * 4 + 5)) * 3
|
||||||
|
((9 * 8 + 9 + 8 * 2 * 3) + 7 * (4 * 6 + 7 * 3 + 2 * 3) + 9) * 7 * 9
|
||||||
|
(3 + 6 + 7 + 9) * (2 + (4 * 7 * 6 + 9 + 3 + 5) + 9 + (2 + 3 + 7 + 4 + 3) + 9) + 8
|
||||||
|
(6 + 8 * 2) + 3 + 7 * 5
|
||||||
|
7 * (5 + 4 * 5 + 9 + 6 * (3 + 4 + 4 + 8 + 4))
|
||||||
|
(4 + 7 * 5 + 4 + 6) + (3 + (5 + 4)) * 3 * (2 * 4) + 2 + 6
|
||||||
|
(6 * 4) + 8 * (4 * (8 + 7 + 3)) + 4
|
||||||
|
5 + 6 * 8 + 3 + (7 * 5 + 5)
|
||||||
|
7 + 2 * 5 * ((8 + 4 * 8 + 3 * 5) + (8 + 4) * 6 + 4 + 9 * 4) * 8
|
||||||
|
(3 * 3 * (7 + 7 * 7 + 7) * 5 * 9 * 9) * 4 * (5 * 2 * 9 + 8 * (4 + 2) * 7) * 9 + 8 * 4
|
||||||
|
5 * 7 + (7 * (2 * 4))
|
||||||
|
3 + (9 + (5 * 9)) + 8 * 4
|
||||||
|
9 * 5 * 3 + 3 + 3 * (9 * 6 * 6 + 2 * 4)
|
||||||
|
2 + ((2 * 7 + 4 * 4) + 8 * 6 * (9 + 4))
|
||||||
|
9 + (8 + (7 * 5 * 7 * 5 * 7)) + 2
|
||||||
|
(4 * 5 * 6 * 3) + 9
|
||||||
|
6 + (2 * 5 * 9 + 8 + 2) * (2 * 8 * 3 * 2)
|
||||||
|
3 * (5 * (3 * 5 + 3) + 5 + (2 + 6 * 8 * 2 + 4 + 6) * 2) * 9 * (6 + 6 + 3) * 2
|
||||||
|
(2 + 5 + 8) + (2 + 8 + 3 * 7 + 4) * 3 + 3 * 9
|
||||||
|
6 * 6
|
||||||
|
5 * 9 * ((6 * 5 + 9 + 9) * 6) * 4
|
||||||
|
5 + 5 * 6 + (3 * 5) + 5
|
||||||
|
3 + (8 + 8 * (6 + 9 * 4 + 8 * 6) + 6 + 7 * 3) + 2 + 8 * 6 * 7
|
||||||
|
(3 * 2 + 6 * 3) * 7 * 6 * 9 + 5
|
||||||
|
2 + ((6 + 4 + 7 + 5 * 3 * 8) * 3 * 5)
|
||||||
|
(3 * 9 * 5 + 3 + 2) * 4 + 8 + (6 + 3 * 8 * 8) * (7 + 5 + 8) + (8 + 9)
|
||||||
|
5 * 2 + 2 * 8 * 5 * (2 * 5)
|
156
www/statics/aoc/2020/18_solution.rs
Normal file
156
www/statics/aoc/2020/18_solution.rs
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
use crate::common::AdventOfCodeDay;
|
||||||
|
|
||||||
|
pub struct Day18 {
|
||||||
|
input: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day18 {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let input_bytes = include_bytes!("../res/18_input.txt");
|
||||||
|
let input_str = String::from_utf8_lossy(input_bytes);
|
||||||
|
|
||||||
|
let lines = input_str
|
||||||
|
.lines()
|
||||||
|
.map(|p| String::from(p))
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
input: lines
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day18 {
|
||||||
|
fn full_eval_lin(formula: String) -> i64 {
|
||||||
|
return Self::eval_lin(&formula.chars().filter(|p| *p != ' ').collect(), 0).0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn eval_lin(formula: &Vec<char>, start_idx: usize) -> (i64, usize) {
|
||||||
|
|
||||||
|
let mut curr: i64 = 0;
|
||||||
|
|
||||||
|
let mut i = start_idx;
|
||||||
|
loop {
|
||||||
|
if i >= formula.len() || formula[i] == ')' {
|
||||||
|
return (curr, i+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut op = '+';
|
||||||
|
|
||||||
|
if i > start_idx {
|
||||||
|
op = formula[i];
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let param: i64;
|
||||||
|
if formula[i] == '(' {
|
||||||
|
(param, i) = Self::eval_lin(formula, i+1);
|
||||||
|
} else {
|
||||||
|
param = formula[i].to_string().parse::<i64>().unwrap();
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
match op {
|
||||||
|
'+' => { curr += param; }
|
||||||
|
'*' => { curr *= param; }
|
||||||
|
_ => panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day18 {
|
||||||
|
// Shunting-yard Algorithm
|
||||||
|
fn eval_advanced(formula: String) -> i64 {
|
||||||
|
let mut operands: Vec<i64> = Vec::new();
|
||||||
|
let mut operators: Vec<char> = Vec::new();
|
||||||
|
|
||||||
|
for chr in formula.chars().filter(|p| *p != ' ') {
|
||||||
|
if chr == '*' || chr == '+' {
|
||||||
|
|
||||||
|
while !operators.is_empty() && chr <= *operators.last().unwrap() {
|
||||||
|
let a = operands.pop().unwrap();
|
||||||
|
let b = operands.pop().unwrap();
|
||||||
|
let op = operators.pop().unwrap();
|
||||||
|
|
||||||
|
operands.push(match op {
|
||||||
|
'+' => a+b,
|
||||||
|
'*' => a*b,
|
||||||
|
_ => panic!(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
operators.push(chr);
|
||||||
|
|
||||||
|
} else if chr == '(' {
|
||||||
|
|
||||||
|
operators.push(chr);
|
||||||
|
|
||||||
|
} else if chr >= '0' && chr <= '9' {
|
||||||
|
|
||||||
|
operands.push(chr.to_string().parse().unwrap());
|
||||||
|
|
||||||
|
} else if chr == ')' {
|
||||||
|
|
||||||
|
while *operators.last().unwrap() != '(' {
|
||||||
|
let a = operands.pop().unwrap();
|
||||||
|
let b = operands.pop().unwrap();
|
||||||
|
let op = operators.pop().unwrap();
|
||||||
|
|
||||||
|
operands.push(match op {
|
||||||
|
'+' => a+b,
|
||||||
|
'*' => a*b,
|
||||||
|
_ => panic!(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
operators.pop();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
panic!();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while !operators.is_empty() {
|
||||||
|
let a = operands.pop().unwrap();
|
||||||
|
let b = operands.pop().unwrap();
|
||||||
|
let op = operators.pop().unwrap();
|
||||||
|
|
||||||
|
operands.push(match op {
|
||||||
|
'+' => a+b,
|
||||||
|
'*' => a*b,
|
||||||
|
_ => panic!(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return operands.pop().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AdventOfCodeDay for Day18 {
|
||||||
|
|
||||||
|
fn task_1(&self) -> String {
|
||||||
|
|
||||||
|
if is_verbose!() {
|
||||||
|
for line in &self.input {
|
||||||
|
verboseln!("{} := {:?}", line, Day18::full_eval_lin(line.to_owned()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.input.iter().map(|p| Day18::full_eval_lin(p.to_owned())).sum::<i64>().to_string();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn task_2(&self) -> String {
|
||||||
|
|
||||||
|
if is_verbose!() {
|
||||||
|
for line in &self.input {
|
||||||
|
verboseln!("{} := {:?}", line, Day18::eval_advanced(line.to_owned()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.input.iter().map(|p| Day18::eval_advanced(p.to_owned())).sum::<i64>().to_string();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
134
www/statics/aoc/2020/19_challenge.txt
Normal file
134
www/statics/aoc/2020/19_challenge.txt
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
You land in an airport surrounded by dense forest. As you walk to your high-speed train, the Elves at the Mythical Information Bureau contact you again. They think their satellite has collected an image of a sea monster! Unfortunately, the connection to the satellite is having problems, and many of the messages sent back from the satellite have been corrupted.
|
||||||
|
|
||||||
|
They sent you a list of the rules valid messages should obey and a list of received messages they've collected so far (your puzzle input).
|
||||||
|
|
||||||
|
The rules for valid messages (the top part of your puzzle input) are numbered and build upon each other. For example:
|
||||||
|
|
||||||
|
0: 1 2
|
||||||
|
1: "a"
|
||||||
|
2: 1 3 | 3 1
|
||||||
|
3: "b"
|
||||||
|
|
||||||
|
Some rules, like 3: "b", simply match a single character (in this case, b).
|
||||||
|
|
||||||
|
The remaining rules list the sub-rules that must be followed; for example, the rule 0: 1 2 means that to match rule 0, the text being checked must match rule 1, and the text after the part that matched rule 1 must then match rule 2.
|
||||||
|
|
||||||
|
Some of the rules have multiple lists of sub-rules separated by a pipe (|). This means that at least one list of sub-rules must match. (The ones that match might be different each time the rule is encountered.) For example, the rule 2: 1 3 | 3 1 means that to match rule 2, the text being checked must match rule 1 followed by rule 3 or it must match rule 3 followed by rule 1.
|
||||||
|
|
||||||
|
Fortunately, there are no loops in the rules, so the list of possible matches will be finite. Since rule 1 matches a and rule 3 matches b, rule 2 matches either ab or ba. Therefore, rule 0 matches aab or aba.
|
||||||
|
|
||||||
|
Here's a more interesting example:
|
||||||
|
|
||||||
|
0: 4 1 5
|
||||||
|
1: 2 3 | 3 2
|
||||||
|
2: 4 4 | 5 5
|
||||||
|
3: 4 5 | 5 4
|
||||||
|
4: "a"
|
||||||
|
5: "b"
|
||||||
|
|
||||||
|
Here, because rule 4 matches a and rule 5 matches b, rule 2 matches two letters that are the same (aa or bb), and rule 3 matches two letters that are different (ab or ba).
|
||||||
|
|
||||||
|
Since rule 1 matches rules 2 and 3 once each in either order, it must match two pairs of letters, one pair with matching letters and one pair with different letters. This leaves eight possibilities: aaab, aaba, bbab, bbba, abaa, abbb, baaa, or babb.
|
||||||
|
|
||||||
|
Rule 0, therefore, matches a (rule 4), then any of the eight options from rule 1, then b (rule 5): aaaabb, aaabab, abbabb, abbbab, aabaab, aabbbb, abaaab, or ababbb.
|
||||||
|
|
||||||
|
The received messages (the bottom part of your puzzle input) need to be checked against the rules so you can determine which are valid and which are corrupted. Including the rules and the messages together, this might look like:
|
||||||
|
|
||||||
|
0: 4 1 5
|
||||||
|
1: 2 3 | 3 2
|
||||||
|
2: 4 4 | 5 5
|
||||||
|
3: 4 5 | 5 4
|
||||||
|
4: "a"
|
||||||
|
5: "b"
|
||||||
|
|
||||||
|
ababbb
|
||||||
|
bababa
|
||||||
|
abbbab
|
||||||
|
aaabbb
|
||||||
|
aaaabbb
|
||||||
|
|
||||||
|
Your goal is to determine the number of messages that completely match rule 0. In the above example, ababbb and abbbab match, but bababa, aaabbb, and aaaabbb do not, producing the answer 2. The whole message must match all of rule 0; there can't be extra unmatched characters in the message. (For example, aaaabbb might appear to match rule 0 above, but it has an extra unmatched b on the end.)
|
||||||
|
|
||||||
|
How many messages completely match rule 0?
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
As you look over the list of messages, you realize your matching rules aren't quite right. To fix them, completely replace rules 8: 42 and 11: 42 31 with the following:
|
||||||
|
|
||||||
|
8: 42 | 42 8
|
||||||
|
11: 42 31 | 42 11 31
|
||||||
|
|
||||||
|
This small change has a big impact: now, the rules do contain loops, and the list of messages they could hypothetically match is infinite. You'll need to determine how these changes affect which messages are valid.
|
||||||
|
|
||||||
|
Fortunately, many of the rules are unaffected by this change; it might help to start by looking at which rules always match the same set of values and how those rules (especially rules 42 and 31) are used by the new versions of rules 8 and 11.
|
||||||
|
|
||||||
|
(Remember, you only need to handle the rules you have; building a solution that could handle any hypothetical combination of rules would be significantly more difficult.)
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
42: 9 14 | 10 1
|
||||||
|
9: 14 27 | 1 26
|
||||||
|
10: 23 14 | 28 1
|
||||||
|
1: "a"
|
||||||
|
11: 42 31
|
||||||
|
5: 1 14 | 15 1
|
||||||
|
19: 14 1 | 14 14
|
||||||
|
12: 24 14 | 19 1
|
||||||
|
16: 15 1 | 14 14
|
||||||
|
31: 14 17 | 1 13
|
||||||
|
6: 14 14 | 1 14
|
||||||
|
2: 1 24 | 14 4
|
||||||
|
0: 8 11
|
||||||
|
13: 14 3 | 1 12
|
||||||
|
15: 1 | 14
|
||||||
|
17: 14 2 | 1 7
|
||||||
|
23: 25 1 | 22 14
|
||||||
|
28: 16 1
|
||||||
|
4: 1 1
|
||||||
|
20: 14 14 | 1 15
|
||||||
|
3: 5 14 | 16 1
|
||||||
|
27: 1 6 | 14 18
|
||||||
|
14: "b"
|
||||||
|
21: 14 1 | 1 14
|
||||||
|
25: 1 1 | 1 14
|
||||||
|
22: 14 14
|
||||||
|
8: 42
|
||||||
|
26: 14 22 | 1 20
|
||||||
|
18: 15 15
|
||||||
|
7: 14 5 | 1 21
|
||||||
|
24: 14 1
|
||||||
|
|
||||||
|
abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa
|
||||||
|
bbabbbbaabaabba
|
||||||
|
babbbbaabbbbbabbbbbbaabaaabaaa
|
||||||
|
aaabbbbbbaaaabaababaabababbabaaabbababababaaa
|
||||||
|
bbbbbbbaaaabbbbaaabbabaaa
|
||||||
|
bbbababbbbaaaaaaaabbababaaababaabab
|
||||||
|
ababaaaaaabaaab
|
||||||
|
ababaaaaabbbaba
|
||||||
|
baabbaaaabbaaaababbaababb
|
||||||
|
abbbbabbbbaaaababbbbbbaaaababb
|
||||||
|
aaaaabbaabaaaaababaa
|
||||||
|
aaaabbaaaabbaaa
|
||||||
|
aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
|
||||||
|
babaaabbbaaabaababbaabababaaab
|
||||||
|
aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba
|
||||||
|
|
||||||
|
Without updating rules 8 and 11, these rules only match three messages: bbabbbbaabaabba, ababaaaaaabaaab, and ababaaaaabbbaba.
|
||||||
|
|
||||||
|
However, after updating rules 8 and 11, a total of 12 messages match:
|
||||||
|
|
||||||
|
bbabbbbaabaabba
|
||||||
|
babbbbaabbbbbabbbbbbaabaaabaaa
|
||||||
|
aaabbbbbbaaaabaababaabababbabaaabbababababaaa
|
||||||
|
bbbbbbbaaaabbbbaaabbabaaa
|
||||||
|
bbbababbbbaaaaaaaabbababaaababaabab
|
||||||
|
ababaaaaaabaaab
|
||||||
|
ababaaaaabbbaba
|
||||||
|
baabbaaaabbaaaababbaababb
|
||||||
|
abbbbabbbbaaaababbbbbbaaaababb
|
||||||
|
aaaaabbaabaaaaababaa
|
||||||
|
aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
|
||||||
|
aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba
|
||||||
|
|
||||||
|
After updating rules 8 and 11, how many messages completely match rule 0?
|
570
www/statics/aoc/2020/19_input.txt
Normal file
570
www/statics/aoc/2020/19_input.txt
Normal file
@ -0,0 +1,570 @@
|
|||||||
|
124: 72 26 | 58 91
|
||||||
|
76: 72 90 | 58 73
|
||||||
|
89: 58 135 | 72 25
|
||||||
|
43: 58 30 | 72 98
|
||||||
|
130: 58 58
|
||||||
|
87: 135 72 | 100 58
|
||||||
|
24: 72 5 | 58 78
|
||||||
|
61: 84 72 | 71 58
|
||||||
|
8: 42
|
||||||
|
68: 49 72 | 91 58
|
||||||
|
103: 126 58 | 124 72
|
||||||
|
132: 58 17 | 72 37
|
||||||
|
75: 72 89 | 58 50
|
||||||
|
99: 72 72 | 58 58
|
||||||
|
28: 58 19 | 72 65
|
||||||
|
2: 9 72 | 67 58
|
||||||
|
113: 58 100 | 72 130
|
||||||
|
66: 129 58 | 70 72
|
||||||
|
74: 72 116 | 58 56
|
||||||
|
45: 72 82 | 58 38
|
||||||
|
70: 137 58 | 12 72
|
||||||
|
78: 72 58 | 58 58
|
||||||
|
115: 78 58 | 27 72
|
||||||
|
48: 58 121 | 72 95
|
||||||
|
23: 120 58 | 93 72
|
||||||
|
44: 58 25 | 72 130
|
||||||
|
17: 58 27 | 72 91
|
||||||
|
65: 102 72 | 46 58
|
||||||
|
19: 72 84 | 58 35
|
||||||
|
79: 29 72 | 127 58
|
||||||
|
13: 58 88 | 72 136
|
||||||
|
6: 15 72 | 130 58
|
||||||
|
81: 58 72
|
||||||
|
100: 117 72 | 58 58
|
||||||
|
116: 78 72 | 49 58
|
||||||
|
136: 20 72 | 50 58
|
||||||
|
97: 53 72 | 85 58
|
||||||
|
107: 58 27 | 72 5
|
||||||
|
0: 8 11
|
||||||
|
49: 58 72 | 72 117
|
||||||
|
88: 105 58 | 21 72
|
||||||
|
83: 69 72 | 5 58
|
||||||
|
112: 58 32 | 72 2
|
||||||
|
47: 62 72 | 118 58
|
||||||
|
59: 58 134 | 72 101
|
||||||
|
60: 132 72 | 103 58
|
||||||
|
55: 58 44 | 72 92
|
||||||
|
67: 72 15 | 58 100
|
||||||
|
96: 81 72 | 135 58
|
||||||
|
121: 25 58 | 26 72
|
||||||
|
39: 58 81 | 72 25
|
||||||
|
82: 81 58
|
||||||
|
27: 72 72 | 117 58
|
||||||
|
85: 58 119 | 72 68
|
||||||
|
53: 72 39 | 58 80
|
||||||
|
91: 72 58 | 72 72
|
||||||
|
129: 58 133 | 72 3
|
||||||
|
18: 58 69 | 72 25
|
||||||
|
120: 110 58 | 36 72
|
||||||
|
114: 58 87 | 72 16
|
||||||
|
34: 72 40 | 58 45
|
||||||
|
29: 58 123 | 72 59
|
||||||
|
36: 15 117
|
||||||
|
133: 58 107 | 72 113
|
||||||
|
109: 58 58 | 58 72
|
||||||
|
46: 100 117
|
||||||
|
41: 109 58 | 91 72
|
||||||
|
26: 72 72 | 58 72
|
||||||
|
72: "a"
|
||||||
|
21: 58 78 | 72 130
|
||||||
|
117: 58 | 72
|
||||||
|
111: 58 5 | 72 81
|
||||||
|
95: 58 27 | 72 109
|
||||||
|
4: 97 72 | 28 58
|
||||||
|
135: 58 117 | 72 58
|
||||||
|
37: 58 27
|
||||||
|
1: 58 99 | 72 25
|
||||||
|
52: 130 58 | 109 72
|
||||||
|
106: 5 72 | 99 58
|
||||||
|
12: 111 58 | 68 72
|
||||||
|
42: 94 58 | 79 72
|
||||||
|
11: 42 31
|
||||||
|
77: 125 72 | 86 58
|
||||||
|
98: 58 91 | 72 109
|
||||||
|
62: 58 122 | 72 52
|
||||||
|
119: 109 72 | 135 58
|
||||||
|
108: 15 72 | 25 58
|
||||||
|
10: 78 58 | 15 72
|
||||||
|
5: 72 58
|
||||||
|
3: 72 33 | 58 37
|
||||||
|
57: 58 51 | 72 7
|
||||||
|
7: 72 43 | 58 74
|
||||||
|
38: 58 91 | 72 15
|
||||||
|
20: 26 58 | 130 72
|
||||||
|
22: 58 99 | 72 15
|
||||||
|
105: 15 72 | 99 58
|
||||||
|
25: 72 72
|
||||||
|
35: 72 99 | 58 91
|
||||||
|
56: 78 72 | 99 58
|
||||||
|
63: 114 72 | 55 58
|
||||||
|
86: 23 72 | 13 58
|
||||||
|
54: 47 58 | 112 72
|
||||||
|
50: 72 5 | 58 99
|
||||||
|
126: 58 81 | 72 26
|
||||||
|
127: 63 72 | 60 58
|
||||||
|
9: 72 27 | 58 15
|
||||||
|
137: 10 58 | 96 72
|
||||||
|
15: 117 117
|
||||||
|
128: 66 58 | 57 72
|
||||||
|
58: "b"
|
||||||
|
14: 18 72 | 116 58
|
||||||
|
92: 58 25 | 72 100
|
||||||
|
40: 83 58 | 131 72
|
||||||
|
31: 77 58 | 128 72
|
||||||
|
69: 58 72 | 72 58
|
||||||
|
125: 34 58 | 76 72
|
||||||
|
110: 117 99
|
||||||
|
94: 72 4 | 58 54
|
||||||
|
102: 72 25 | 58 109
|
||||||
|
30: 58 91 | 72 5
|
||||||
|
84: 99 117
|
||||||
|
93: 50 72 | 6 58
|
||||||
|
80: 72 100 | 58 91
|
||||||
|
64: 58 5 | 72 130
|
||||||
|
51: 58 61 | 72 48
|
||||||
|
122: 5 58 | 25 72
|
||||||
|
16: 58 130 | 72 78
|
||||||
|
90: 22 58 | 106 72
|
||||||
|
131: 58 91 | 72 130
|
||||||
|
123: 14 72 | 75 58
|
||||||
|
33: 58 15 | 72 26
|
||||||
|
71: 27 72 | 69 58
|
||||||
|
73: 104 58 | 24 72
|
||||||
|
32: 72 126 | 58 41
|
||||||
|
134: 72 1 | 58 35
|
||||||
|
101: 72 84 | 58 115
|
||||||
|
104: 130 58
|
||||||
|
118: 64 58 | 108 72
|
||||||
|
|
||||||
|
baabababbaababbbaabbbbab
|
||||||
|
baabababbbabaabaabbbbbbb
|
||||||
|
bbbabaaababbbbaaababbabbaabbabba
|
||||||
|
bbbbbbaaaababbaaaababaaabbaaababaaababba
|
||||||
|
bbabbaaaabbbabaaaabbbbbbabbbbbaa
|
||||||
|
aaaabaaabbbabbaaaabbbbbabaabbbaabbbaaaabbababbbb
|
||||||
|
bbbabababbbbbbbbbbbbabbbababbaba
|
||||||
|
aabbbbaaabbabbabaaaababaabbbabbbbabbaaabaaaaabbbbaaababbabbbbbbabbbbaaababbbbaab
|
||||||
|
bbababbaaabbbbbbabaaaabbbbbbabba
|
||||||
|
babaaaabbaaabbbabaaaaabb
|
||||||
|
bbbabaaabaaabbbabababbaaabbbbbabababababaaaaaaba
|
||||||
|
bbaabaabbbaaaabaabaaabaa
|
||||||
|
bbaabababbaaabbbaaaaabaabababbbbbaaabbaa
|
||||||
|
babbbbaaaaaaaabbabbabbba
|
||||||
|
bbbbbbabababbabbbbbbbbba
|
||||||
|
bbaaababbaaabbbbaababbbababaaaabaabbbaaaabbbabbabaaabbab
|
||||||
|
bbaaaabaaabbbaaabbaaabaa
|
||||||
|
baabbbaababbbbaaaaabbbbbbaaababbbbbbaaba
|
||||||
|
abbabbbabaaaaaaabbabaaabaaabababbabaaabaaabbbaaa
|
||||||
|
aababaaababbbaabababbabbabbbabbbbaaaababaabbabab
|
||||||
|
ababbbbaaaaaaaabababaabb
|
||||||
|
ababbbaaaaaabbabbaaabbabbabbaabbaabaaaab
|
||||||
|
bbaabaabaaabbaaabbbbbbbb
|
||||||
|
babaababbbbbbaaabbababba
|
||||||
|
bbaabbaaaaaabbbbabbbabbbabaabbabababaaba
|
||||||
|
bbbbbaaababbabaabbbaabbaaabbbbababbabaabaaaaaabaaabababaaaaaaaabaaaaababbbbbaabababbabbb
|
||||||
|
aabbbabababbaaabbbbaaaabbabbbbbbabaabaab
|
||||||
|
abbbabbaabbbababbbababbabaabaaabbababbab
|
||||||
|
baaaabaaaaabbababbaaaaaabababbbbabbbbababaaaaaaaabbbabab
|
||||||
|
aabaabababbabbbbbaabbaabbbaabbba
|
||||||
|
aaaabbbbabbabbabbaabbaabbaaaababababaaaabaabaabbabbbbbaabaaaaaba
|
||||||
|
bbbaaaabbaabbaababbabbbaabaababbbbaabbbbbbaabaaaabbbbaabaaaaabba
|
||||||
|
babbaabbaaaabbababaaabbabababbaaabbbababbbbbaabb
|
||||||
|
aabbbbaaabbbabbbabbababa
|
||||||
|
aaabaabaabbaaaabababaaabababbaabbabaaabbabaababaabbbaaab
|
||||||
|
aabbbabbbaababbbbbaaabaaaabaabaabaabaabbbaabbbaabbbaabba
|
||||||
|
bbaabbaababbbaabaaaaaabbbbbbbbba
|
||||||
|
ababbabbabbbaabbabaababaaaaaaaaabbbaabaabbbabbba
|
||||||
|
bbbabbabbabbbabbabbaaaaabbabbbabbbaaababababbabbbaaaaaaaaaababaaaabaabaaabbbababbbbaaaab
|
||||||
|
babaaaabababaaaabbabaaaababaababbabaabbabaabaaabaabbabba
|
||||||
|
aaabaabaabbbaabbbbbbabbababbabab
|
||||||
|
baababbbbabaabbaabbbaaaaabbabbbabbaabaabbababbaabbabbbbaabbbbbbb
|
||||||
|
ababbaababbabbbbbaababaaababbaba
|
||||||
|
baabbbabaaabbaababaaaabbbabbbaaaaaaaabaaaabbbbabababaabbabaaaabb
|
||||||
|
bbbaaababbbbbbaabbbbabbb
|
||||||
|
bbbaaaabaabaababaaabbaaaabbabbaaaaaaabbbaaabbabbbbabbaababbaaababaaabbaa
|
||||||
|
aabbbabaaaaaabbbabbabbba
|
||||||
|
aaaaaaabababbbabaabbbbba
|
||||||
|
aaaaaaaaababbbaababababbbbbabbbbabababaaabababaabbbbbaba
|
||||||
|
bbaaaaabababaababbbaabbababbaaababbabababbababbaabbababbabaababaaabababbbbbbaaba
|
||||||
|
bbaaaabbaaaaaaaababbaaaa
|
||||||
|
aaaaabaababaababaaababaa
|
||||||
|
babaabbbbaaabbbabbabbbbbbaaabbababaaabaababbaaaa
|
||||||
|
bbbbbbaabababbaaaaabbbbabaabbaba
|
||||||
|
abaaabbbaababbaaaababbbbbbaaaaababbabaaabbbaababaaababaa
|
||||||
|
abbabbbabaaabaabaabbbabbbabbbabaababaaaaaaaaaaabbbbabaaaabbababbbaaaaaaababbabbbabbbbaab
|
||||||
|
aababbaaaaabaababbbaaabababbababbbbaabbbbabaabbbabaabbaa
|
||||||
|
bbaabababbbbaababbaaabbabaaaaabbbabababa
|
||||||
|
aabbbabaabbbaabaaabbbabaabaababababbaaba
|
||||||
|
bbabbaabbbbbbbbabbbbbaaaaabbaaabbbbabbbbbaaabbabbbbbbbbbbbbbbaababbaaabbaaaababbbbbbaaab
|
||||||
|
abbbababbbaaaaaabbbabbabbbbabbabbbabaabb
|
||||||
|
aababbaaabbbaabbababbaaa
|
||||||
|
abbabbbbbbbbaababaaabbbb
|
||||||
|
aaabbbaaaaabbbabbabbaaaa
|
||||||
|
ababbbbbabbabaabaaaaabaaabbabbaabbbbbaaa
|
||||||
|
aaaabbbabbbbababbbababbaabbbaabbaaababba
|
||||||
|
aaabbbabbbaabaababbbaaabbaaaababaabbabaababbabaa
|
||||||
|
baaaabaabaaabaabababaaba
|
||||||
|
abbbabbbabbbabbaaaabbaab
|
||||||
|
bbabbabbbaaaababbbaaabbaabbabbbbaabbbaaaabbbaabbaabbababababaaba
|
||||||
|
abbabbaaaababababaabbbaa
|
||||||
|
ababbbaabaaabbbabbbabbab
|
||||||
|
bbaaabbbbaaaaaababbbaababbabbbaabbaaaabb
|
||||||
|
bbabbabbaabbababbaabbabaaaabaaaaabababaaaaabbaab
|
||||||
|
bbaababaaaabbbaaaabbbbabbbabaabb
|
||||||
|
bbababbaabaabbbababaababaabaaaab
|
||||||
|
bababaaaaaaabbbabbbbaabaabbbabaababbbabbababaaba
|
||||||
|
babbaabbbbbbababbbabbbbbbaaaaaabbabbabaaaaabbabb
|
||||||
|
babbbabbabaaabbabbbbaaaa
|
||||||
|
aaaabbabbbababbabbaaaabaaaabbbaa
|
||||||
|
abbbaabaaababaaaabbabbbbbbbaaaaabbabaabbababbaaabbbbbbbabaabaabb
|
||||||
|
abbbabaaababaaaaaabaababbbababbaaabbabaabbbbaaabbbbbbaab
|
||||||
|
babbaabbbbbaababbaaabbbbabbaaaaa
|
||||||
|
babbbbbbbbbabaaabaabbbba
|
||||||
|
bbbaaabaabaaaaabbaabbababbaabbabbabbababbabbbabaaabbabab
|
||||||
|
aabbbaaaababbaabbbabaaab
|
||||||
|
bbbbbbaaababbbaabaababba
|
||||||
|
bbabbbbbbbabaababbbabbba
|
||||||
|
babbabaababbbaaababbabababbbaabbbbaaabbbaaaabbababaababb
|
||||||
|
ababaaaaaaaaaaabbbaaaabbbaabbbbb
|
||||||
|
abbbaaaaaaaaabbaababaabb
|
||||||
|
baabaabaaabbbabaabbabbabaabbbbba
|
||||||
|
abaaabbbbbabbbbbbbbaabbbbbaaaabbbbbaabbbbbabbbababbaabaa
|
||||||
|
aaabbbaaababbbbabbbbabbabaabaabb
|
||||||
|
abbabbbbbababaaababbabababbabbbbbaaaaaabbbaabaaaaabaaabb
|
||||||
|
ababbabbaabbaaabaaababbb
|
||||||
|
bbbabaaaabaaaaabbaabbaabbbaababaaaaaababaaabaaabbbbbabaa
|
||||||
|
babbbababbbbbbabaaabaabababbbbbbbaaabbbb
|
||||||
|
aababaaaababbbaaababbbaababbbaaabbbaabbaaababbba
|
||||||
|
ababbbbaaabbbaaaaabaababaaaaaaaaabbababababbaaba
|
||||||
|
aabbaaababbabbaaaaabbbaa
|
||||||
|
bbbbaaabbaabbababaabbbabbbabaaabbbabbabababaabab
|
||||||
|
babaababbbbbabababbabbbbbbbbaaaa
|
||||||
|
abbbabaaabaaabbbaaabbbaaaaabbabaabbabbaaaabbaabaaabaaabaabbbbabbbabaaabbaababbaabbabaabb
|
||||||
|
aaabbbbaabbbababababbabbabaaabbabaabaabb
|
||||||
|
aaabbbaabbbbababbbaababb
|
||||||
|
baabababbbbabbbabbaabbababbbaaabaaababbb
|
||||||
|
bbbabaaaabaaaaabbbababab
|
||||||
|
baaaaabbbabbabbbbbaaaabaababbbbaabaabbabbbaaabbaababaaba
|
||||||
|
abbaaaabaaabbaaababbabababbbaababbbbbbaabbbbbaaa
|
||||||
|
baabbbabaababaaaabbababa
|
||||||
|
aabbbabbabaaaaaabbbbbaba
|
||||||
|
aabbbbaaaaaaababbaabbbaababbabbbaaababbbabaabbbbbabbaaaa
|
||||||
|
aabbaabbbabaaaabbbabbaab
|
||||||
|
aabbaaaaabababbbabaaaaaabbbababbaababababbaabbabaaabaaaababbbbab
|
||||||
|
bababbaaababaaaabbbbbbbb
|
||||||
|
aaaaababbbaaaabbbbaabbab
|
||||||
|
baabbaaaaabbbaaabaaababa
|
||||||
|
bbbabbbabbaabaaabbbbaabbbbabbbaabbbaaaababbababbbaabababbaabaaab
|
||||||
|
bbababababbababbbaaabbaaabbabababbbbbbaabaababaa
|
||||||
|
aababbaabaaaabbbabababaa
|
||||||
|
aaabbaaabbbaaaabbbbbaaaa
|
||||||
|
bbabbabbabbaaaababbababa
|
||||||
|
bbbabaaaaaabbaaaaabbabbbaaabbabaabbabaaa
|
||||||
|
aaaaaaaabbaababaaabbbbaabaabababbbbbbaab
|
||||||
|
babbaabaababaabaabababaabbbbbbba
|
||||||
|
aababaaaababbbbbbabbabababababaaabbbaaab
|
||||||
|
baabbbaabbbbbbbbabbaabbb
|
||||||
|
baababbbabbabbabaaaaaababaaabaaa
|
||||||
|
ababbbababbbbbabbaabbbaa
|
||||||
|
bbaababaaabbbbaaababaaababbababa
|
||||||
|
bbabbaaaabbabbbbaaabaaab
|
||||||
|
abbbabbabbabaabaaaaaaabbabbbbbbbbbbbbaaa
|
||||||
|
abbaaabbbbaaabbbbaababbbaaaabaab
|
||||||
|
bbaabababaaabbbaabbaabbb
|
||||||
|
ababbabbaaabaabaaaaaaaabababaaababaaabbbaabbabaabbbbbaba
|
||||||
|
aababababaaaababbabaaaababaaabbbbaaaaaba
|
||||||
|
babaaabaabbbbbbbabbbbbbbbaababaabbaaabaa
|
||||||
|
bababbbabaabbbabaaabbbaaaaabaababaabbbaabbbbbbba
|
||||||
|
ababbbabbbaaaabaabaabaaa
|
||||||
|
ababbbbaaabbaaabaababbbbaaaaaaaaabbababb
|
||||||
|
bbaabaabaaaabbabaaaaaaabbabbaaaaabbbbbbb
|
||||||
|
aabaaabbababbbabaaaabaabbbaababb
|
||||||
|
babbbbabaaaabababaababbabaaaabbabbabaaabaaabbbbbbbaabbbb
|
||||||
|
babbaababbbbbbbabbabaabbbbabbaaaababaaaa
|
||||||
|
baabaabababbbbabbaaabaaaabbbaabaaabaabbabbbbabbbabaaaabababaaaabbbbbbabb
|
||||||
|
bbbabaabaabbbabbbaabbaabaabaabba
|
||||||
|
babbbababbabbabbabbbaabaaaaabbbbbabaabbbabaaaabbbaaabaaa
|
||||||
|
aaabbbaababbbaaaaaabbbbaaaaaabbbaaaabbaaaababbbabbbabbba
|
||||||
|
babbaabbababbbbaaababbaabbaaaaaa
|
||||||
|
abaababaabbbabaaaaabbaba
|
||||||
|
abbabbabaabaaaaaaaabbaba
|
||||||
|
bbbbbbaaababbbbaabbaaabbaababbbaaaababbb
|
||||||
|
abbaaabbbbbbababaabaaaaaaaaaababbbbabbaa
|
||||||
|
abbbabaaaabbaabbaaabababbbbbaaaa
|
||||||
|
bbbababbaababbbbbbaaabbbbaabbababaaaaabb
|
||||||
|
abbaababaabbbabbabababab
|
||||||
|
ababbaababaaabbbbababaaaaabababaaaabaabb
|
||||||
|
aaaaababbabbabaababbabba
|
||||||
|
aabbaababbaabaaaaaabbabababaaaaa
|
||||||
|
bbabbabbaabaabbbbababaaabbbababbababaabb
|
||||||
|
babaaababbababbabbbbbbaabbbaaaaabbaaaabbbaaaaabb
|
||||||
|
aaabaabaaaaaabbbaaaabababaaabbbbbbbbabbbbaababababaabbbaabaaabaabbabbbba
|
||||||
|
baabababbabaaaabababaaabbaabbbba
|
||||||
|
abaaaaaababbbaababbbbbba
|
||||||
|
baabbaaabaabbbabbbabbbaa
|
||||||
|
ababbbbbabaababaaabbabba
|
||||||
|
abbaaabbbabbaaabbbbbbaaa
|
||||||
|
ababaaaaaabbaabbbbbaaaaaabaabbbabbbabaabbababbabbbbbaaababbbbaab
|
||||||
|
aabaaaaaaaaabaaabababbbaababaabaaaaabbababaabbababbaaaabbbabaaba
|
||||||
|
babaabababababbbaaabbbaaaabaaaabaaaabbbbaaababaaaababbaabaabaaabababaabb
|
||||||
|
ababbaabbbabbaababbababa
|
||||||
|
ababaaabbbaaabaabbbababbbaabaaabaabaaabb
|
||||||
|
aabbbabaaabaabababaaabbaaaabbabbaaababbb
|
||||||
|
baaabbabbbaaaababaaabaabbaaaabbbabbaaaabaaaabaabbaaabaaa
|
||||||
|
baaaababbaabbbbaaaaabbba
|
||||||
|
bbababbaaabaababbbbbbaaa
|
||||||
|
bbbaaabaabaaabbabaabaaaa
|
||||||
|
aabbbbaabaababbaaaabbaab
|
||||||
|
ababababbbbabbbaabbbbabbbaaababb
|
||||||
|
abbaaabbbaaaabbabbbbbaba
|
||||||
|
aababbaaaaaaababbabbaaba
|
||||||
|
abbaaabababbaabaaaaaaabaabbaabaabaabaaababaaaaba
|
||||||
|
abaabbbababbbbaabbbbaabb
|
||||||
|
abaaabbaaaaabbbbaaabaaaa
|
||||||
|
bababbbbbaabbbbbbababbababbbbaba
|
||||||
|
abbbabbbabbaaaabbabbbaaaaaabaabababbbbbaabaaabab
|
||||||
|
ababbbbbbabbbbabaaaaabba
|
||||||
|
baaabbabbaaaaaaaaabbbbaabbbbbaba
|
||||||
|
aabaaabbabbaabbabaabaaabbabbababaaabbaabaababaab
|
||||||
|
abbbbabbaaabbaaaabbbbbaaababbbbbbbbaaabbbabbaaab
|
||||||
|
ababbaabbbbabaaaabaabbaa
|
||||||
|
abababbababbabaabbaaaabaaaaaaabbaaaaaaabaababbababababbbaababbba
|
||||||
|
aaaaababbaababaaabbbaaababbbbaabbbbabbbaababbaaa
|
||||||
|
bbaaaaabbabbaabbbbbbbbba
|
||||||
|
ababbabbabaaabbbaabababa
|
||||||
|
bababbbaabbaaaaabbbbbaab
|
||||||
|
abaaaaaabababaaabaabaabaaaaabaaa
|
||||||
|
abaaabbaaababaaabbbbbabaababbbbbababaabababbbbbaabbbabbbabbaaabaababbaabbaabbabb
|
||||||
|
ababaaaabbaabaaaabbabbba
|
||||||
|
bbbabaaabbbabaaaabaaaaabbababbaaabababbb
|
||||||
|
bbabbabbbaaaaaabbbbbbbbb
|
||||||
|
bbbbbbaabbaabaabaaabbabb
|
||||||
|
bbbabaaabbabbabbaabbabba
|
||||||
|
aabaababaaaaaaaaaabbbabaabbbabbaabbbbaabbbbbaaaa
|
||||||
|
abbaaabbaaabbbbaaababbab
|
||||||
|
abaabababbbabaabbaaaabaaaaabbabbabaabaaa
|
||||||
|
babbbaaabaabbaabbbbaabbbabbbabbababbbababbbabbaa
|
||||||
|
aaaaaabbbbbaaababbaababb
|
||||||
|
abbaaabbbbbbabbabbaabbab
|
||||||
|
bbbbabbaabaababaaaaabababaaaabba
|
||||||
|
baaababbbbaaabaaaabababbbbaabbbbbbababab
|
||||||
|
babbbbababbbabbbaaabaaab
|
||||||
|
bbaaabbbbbbaabaaaabbbbbbababbbabaaababbabbbbbaba
|
||||||
|
bbabababbababbbabbbbbaabbaababbbbbaababaaabbabbababbaaaaababbbbabaaabaabbbbabbaaaabbbaba
|
||||||
|
bbaabbbababbbbbbbaaabababbaaabaabbababbaabaaabaababbbaabbbbbbbba
|
||||||
|
baaaabababbaaaaabbabbbbabbbababb
|
||||||
|
aababbbbbabbaabbbbaaaaabaabbabbabaaababa
|
||||||
|
babbbbaaababbbabbbbbabababaaaaaaabbaaaba
|
||||||
|
babbaabbabbabbabaaabbbaabababaaababbabbaaababaabbabbabbb
|
||||||
|
bbaabaabaabaabbbababaabb
|
||||||
|
aaaabbbababbababbabbabaaaaabbbbabbbababbbbbabbbbbaaaaabb
|
||||||
|
aabbbbaababbbbababbbbabbbaaabaaa
|
||||||
|
aaabbbbbabbbaaabbaababaa
|
||||||
|
babaaaabaabbbaaabbaabbaa
|
||||||
|
aaaaabbbaaabbbbabaaabbabbabbbababbabbbab
|
||||||
|
bbbbaababaabababbabbabbb
|
||||||
|
abbaababbbaaaababbbaaabaaabbabaa
|
||||||
|
ababbaabaaabbbabbaabaaab
|
||||||
|
baababbbabaaaaaaabbbabbabbabbabaaababbba
|
||||||
|
baaabbbaaabbbaaababbabaabbbbbaba
|
||||||
|
bababbbbababbbbababaababbaabbbaabaaabbbbababaababbbbabbbbabaaababababbaababbbbaa
|
||||||
|
abbaaaaabbbbbbababbbbaaa
|
||||||
|
bbaabbababbbbaaaabaabababaaaabbababababbbbababbb
|
||||||
|
abbbabbaabbaaabbaaabbaba
|
||||||
|
aaaabbbababbbbabaababaab
|
||||||
|
bbaabbaaabaabbbababaaaabbbaabbbabbbabbab
|
||||||
|
babbbbbbbbababbaabaababb
|
||||||
|
bbbbabbbaaabbbbbaaaabaabaababaababaabbbb
|
||||||
|
babbbabbaababbaabaaaaabb
|
||||||
|
abbbabbbaabbbabbbbaaaaba
|
||||||
|
babababbaabbabbaaabbbbab
|
||||||
|
baaaabaaaaabaabaabbaaaba
|
||||||
|
ababbaaabbbabbbbabababbabbbbabbb
|
||||||
|
babaabababaaabbabababbaaaabaabaa
|
||||||
|
bababbaaabbabbabaaababaa
|
||||||
|
baaaabaaaabbbbbbabbabbba
|
||||||
|
aabbaababaabbbabbabbbbbbbabbbabbaaaaabba
|
||||||
|
abbaabbbabbbbbaabbaabbbbbbbbaababababbabababbaab
|
||||||
|
ababbbbbabaaaaabbbbaaababbbaabbbaaabaaaabaaaaababaabbbaa
|
||||||
|
babbababababaaaaaababbab
|
||||||
|
babaaabbabaaaaaabbbbaaaa
|
||||||
|
bbbbaaaabbbabbbabaabaabbbbbabbab
|
||||||
|
bababbaaabbbaababababaaaabbabbbbbbbaababbabbabba
|
||||||
|
ababbbababaaaaababbabaaa
|
||||||
|
bbbbaababababaaaababaabb
|
||||||
|
baaaabbbaabababababbabba
|
||||||
|
aabbbabbaaabbbabbbaaaaabbbabbaabaaaaaaaabbaaaabaabbaabaa
|
||||||
|
aabaababaababbabbbbaababaabbbbabaaabbbbbaaabaaabbababbab
|
||||||
|
abbabaabbbabbbaaabbaabba
|
||||||
|
aababaaaaababaaabbaaaabbabbbbbaaabababaa
|
||||||
|
baabbaababbbbaabbabbbaaaabbabaaaaaaabbbabbbaaabaaaabaaabbbaabbaaabbaabbbaabbabaaaaaabaab
|
||||||
|
babbbabbbaababbbabbabaaa
|
||||||
|
aaababababbbaabbabbabbba
|
||||||
|
babbbbbbaaabbaaabbbbbaab
|
||||||
|
abbbaabbaaaaabbbbbabbbab
|
||||||
|
bbaabababaabbbabbabababa
|
||||||
|
bbabbbbabbbaaaabbaabaabaaabbbabbbbbababb
|
||||||
|
abbabbabbbbbaabaababbbbbbbababbaabbbbbbaaabaaabbbbaabbba
|
||||||
|
bababaabaababaaabbabbbbb
|
||||||
|
babbaabbbbaabaabbbaabbbabaabbaaabbbbaaabaabbabba
|
||||||
|
bbabbaabababbbbabbbabaaa
|
||||||
|
baabbaabaaaaabaabbaaabab
|
||||||
|
aaabababbabbbaaabaaaabbaaaabbbaabaaaabbbabbbbbabaaaabaababbbbaab
|
||||||
|
baabbbabaabababaaaaabaabaaaaabaaaaaaabbaaabbbaabaabbbbaabaaaabba
|
||||||
|
bbaabbaaaabbbaaaabaaabab
|
||||||
|
baaaaaaaaabbbababaaaaabbaabbbbbabbaaabab
|
||||||
|
aabbaabbabbbaaaabbbabbaaabaabbbbababbaba
|
||||||
|
abaabbbaaaabbbaabbaaaabbbaabbbbb
|
||||||
|
bbbbabbbaaabaabbaaaaabba
|
||||||
|
babbabaabaaababaabaabbabbbaaaaaa
|
||||||
|
abbbbaababbbaabbabaaabbbbaaaaababaaabababbbbbaab
|
||||||
|
bbaaaabbbbbbaaabbababaabaaabbbaababbbbabaaabbababbbababaaaaaabbbbbababba
|
||||||
|
baaaabbbbbbbabbabbaababb
|
||||||
|
bbaaabbaabbbaaaabaabbaba
|
||||||
|
abaaaaabbbbbaabaaababbbbbbbaaaab
|
||||||
|
aaaabbbaababaaabbbbbabbabbaaaabbaababababbbbbababaabbababbbbaaaabbbaaabb
|
||||||
|
abaaabbbbbbaaaaabaabbbaa
|
||||||
|
aabaababbbabbbbaaaabbbaabbaaaaabaaabaabb
|
||||||
|
bababaabbababaabbbaaabaa
|
||||||
|
baaaaaabbabaabbbbabaaabbbbabaabb
|
||||||
|
bbabbbbbabbabbababbaaabbbabbababbaabbbbbbbbabbaa
|
||||||
|
aabbbbbaabbbabbabababbbaaabbbbbaaaabaaab
|
||||||
|
bbbabaabaabbbabababbabaababbbbbababbaaaa
|
||||||
|
aaaabababaaababbbbbbbababbaabbbbbbbbaabbaababbbbaaababaaabbbaababaabbabbbbbbbbbb
|
||||||
|
aaaabaaabbabbabaabbbaaab
|
||||||
|
aaaabaabbbbaaaabbaaabaabbababababbbaabaaababbabaaabbabaa
|
||||||
|
bbbabaaabaaaabbaabbbbaab
|
||||||
|
abbabbbbbbabaaaababbbaabbaaaaababaabbabbbbbaababbabaaaaa
|
||||||
|
abbabbaaaaaabababaaabbabaaaaabaabbbaabbaababaaba
|
||||||
|
aababbbabaababaaabbbaabbbbbbabaaaabbaababababbaaaaaaababbbbbbabbaababbbaaababbaabbbbabab
|
||||||
|
abbaaaabbbaaaaabbaabbaaaaabbabbbbbbabaabaabbabbbbbbabbbaabbababb
|
||||||
|
baababbaababbabbbaabbaba
|
||||||
|
bbababbaabbaababaaababbabbaaaaabbbabbabaabbbbababbabbbabababaaaa
|
||||||
|
aabbbbababababbaabaabbaababbbbba
|
||||||
|
abaaaabbaaabbaaabbabbbaa
|
||||||
|
abbaaabbabaabbbabababaabbbbaabba
|
||||||
|
ababaaababaaabbbabaaabaa
|
||||||
|
aabbaabaaabbbbaabaabaaab
|
||||||
|
aabaabbbabbaaaaaabbbbabaaabaabbaaaababbbaabbabbabbbbaaaaabbaabaa
|
||||||
|
baaabaabbaaaaaaabaaaaaabbababaaaabbbababbbbbaaaa
|
||||||
|
aababbbabbabaaabbababaaaabaabaaaabbbaaba
|
||||||
|
abbabbbabbbabaaabbabababbbabaaaabbaaaaaaaaabababbbabbbab
|
||||||
|
bbbabaaaaaaabbabababbaabaaaaabaaabaabbbabbbabbbabaababbbbbababbbaaaaabbb
|
||||||
|
baabababaaaaabbbbbbabbbb
|
||||||
|
abbaaabbaaabaabaabaabaab
|
||||||
|
abbbbbabbabaaababbabaabbbbabaaaaabbbbaabbaaabababaabaaaabababbbabbabbbaaabbaaabbababbabb
|
||||||
|
ababaaababaabbbabbbbaabb
|
||||||
|
bbaababaabababbaabbbabbbbbabbabaabaabbaa
|
||||||
|
babaabbbababbbbabaaaababbbaaaabababababaabababab
|
||||||
|
bbababbabbbbababaabbabaa
|
||||||
|
bbaaaabababaababaaaabbbaabaaaaabbaabbbabbbbaabba
|
||||||
|
bbabaababbbabaabaabaababababbbaabbbbbaabbbabbaba
|
||||||
|
bbababbabbabaaabaaaabbbb
|
||||||
|
baababbbbbaabbaaabaabaaa
|
||||||
|
abaaaaaaabbaaaababaabaabbbbbaabbbaaababb
|
||||||
|
abaaaabbbabbabababbbbaaa
|
||||||
|
abbbababaabbaabbbaaabbaabbbabbbbaabbbbbabbbbaabb
|
||||||
|
aabbaabbbbabbaaaaabbbbba
|
||||||
|
bbbbabbaabaaaabbbaaababbabbababa
|
||||||
|
babbbabaaabaaaaaabbbbbabaabbabab
|
||||||
|
baaaaaababbbababbbbababa
|
||||||
|
baabbaabaabaaaaabaaabaabaaaabaabaabbbbba
|
||||||
|
aabaabbbbabbababaaabaabaaabaabaa
|
||||||
|
aabbaabbbabbabbbbababaababaaaaabbbaababaabbabbaabbabaaabbbabbaab
|
||||||
|
bbabbaabbabaaabaabbbaabbbbbaaaaaaaaabbaaaabaabaa
|
||||||
|
babbaaabbabaabbbaababbba
|
||||||
|
aaaaabbbbbaaabbaabbabbaabababbbbaaababba
|
||||||
|
babbbaaaabaaabbabaaabbabbbabbaabbbababbb
|
||||||
|
babbbabbbabbbbaabababbaaabababbbbbaababbbbaabaaabbbbaabb
|
||||||
|
bbabbbbbaabbbabbbabaabbbabababaa
|
||||||
|
abbbabbabaaabbbbaaaabaaa
|
||||||
|
babbbbaabaaaaaababaabbbb
|
||||||
|
aaaababababbbaabbbbaabbbbabbaaabbbaaaaaa
|
||||||
|
abbbaabbbababaaabaaaaabb
|
||||||
|
bbaabbaabbaaabbabbaaabbaabaabaabbaaabbbb
|
||||||
|
bababbababbabbbbabababbaaaabaabaaabaaababbaabaabbbabbabbaabbabbbaaaaaaababaaabba
|
||||||
|
abbababaaaabaaabbaabbaba
|
||||||
|
baaababbbabaaabaaaaabaaaabaaaaababbbbbbbbabbabbbabbbabaabaababbabaaabbaaaaabaaabaabaaabababbbaab
|
||||||
|
bbaaabbbabbabbaaabababab
|
||||||
|
aabababaabbabbbbbbababbaaaaabbbbabbbbbba
|
||||||
|
aaaaaabbaaabababaababaaabaaababb
|
||||||
|
abbabaabbbbaaaaaabbaaaba
|
||||||
|
abbbababaaabaababaaaaaaababaaaababababbbaabbbbba
|
||||||
|
abbabbaababbbbababbaaaabbbbaabbbbabbbabbbabbabba
|
||||||
|
bbbaabaaaaabbbaababbaabbbbbabaabbaaababaaaaababb
|
||||||
|
bbaaaaababaabaaabaaabbaaabbaababbbbaaaabbbbbbaba
|
||||||
|
bbaaaabbabbbbbbbaaaaaabbabbbbbabaababbaabaaabaabbbabaaabbaaabbbabbbabaabaaaabbaaaabaaabb
|
||||||
|
abbabbaabbaaabbbbabbbbaabbaabaababaabaaaabbbaaababaabaabaaabaaab
|
||||||
|
abbbabaaaabbaaabbbbabbaa
|
||||||
|
baabaaaabaaaabbaabaaaaab
|
||||||
|
aabbbabaabaaabbbbabbabba
|
||||||
|
bbababbabbbaabbbbbbaaaabbaaabbabbbaabaaa
|
||||||
|
aaaabbbbbaaaababaabababababaabba
|
||||||
|
aabbbabababbbaaaaaabbbbaaaabaaaa
|
||||||
|
abbaaaabbababbbaabbabbabababaababbbaaabb
|
||||||
|
baaaaaabbbabaaaaabbaabbb
|
||||||
|
aaaaaaabbbaaaabaabaaabaa
|
||||||
|
aabbbbbbbbabbaabababaaba
|
||||||
|
bbbbbbaaaaabbaaaabbaabbb
|
||||||
|
bbaaabbbbabaaabbbaaaabaaaabbaabababbbabbabaaaabaabababbb
|
||||||
|
abbbbbabaabbbabbbbbababb
|
||||||
|
abaababaabbbaabbabbbaababbababbbbbbbbbba
|
||||||
|
aabbbabaaaabbaaabbaabbaaabbbbaaa
|
||||||
|
aabbabbbaaaabbabababbaba
|
||||||
|
aaabbbbababbbaaababaabbbbaabbaba
|
||||||
|
aabbbababbabbaaaabbaaaaaaaaaaaaabbbaabbaaabababb
|
||||||
|
ababbbabbabaaababbaabbbb
|
||||||
|
aabbbabbbaabbbabababbabbabbbabbabaaabbbabaabbbbb
|
||||||
|
abbbabbaaabbbababbabbbbbbbbbabaabaaaaabbabbbbababbbababb
|
||||||
|
baabaababaaaababbababbbb
|
||||||
|
bbaaaaaabaabbbaaaaaabbbaaabbbbabbbaaabbbbbbbbbbbabbbbaaababaabaaaaaaaaabbbabaababaabaabb
|
||||||
|
aababbbbabaaababbbabbaaaaaaaaabbaabbbbbaaababababababaababbaabababababbbabbbababbbaabaab
|
||||||
|
bbabaabaaabbbbbbbababbaa
|
||||||
|
aaababbabbbbababaababaabbbababaabbbabaababaaaabbaabbbaaa
|
||||||
|
bbababbaaabbbaaaabbaabbb
|
||||||
|
aabbbabaababbbaabbbabaaaaaaabbbabbbbbbaaabbababaabbaaabaabaabbaa
|
||||||
|
ababbbaaaabaabbbbbbbbbbb
|
||||||
|
abbbabaababbabaababaabba
|
||||||
|
aaabbbaababbabaabbbbaababbabbbab
|
||||||
|
bbaaaababaaabbbabbaababbababbababaaabaaa
|
||||||
|
bbaaabbaabbaababaaaaabbbbaabbbaaabbbbaaa
|
||||||
|
aaaaabababbbaaaabbbbbbabbabbbaababbabbaabbbbaabb
|
||||||
|
aaabbaaaabbbabaabbbbbabbbbaababbbbbbbbbabbaaaabaabbbabbbaaaabbabbbabbaaaaaaaabbbbbabaaba
|
||||||
|
babbbaabbaabaabaaaaabbbabbbbaabaaaabaabbbbabaabb
|
||||||
|
abbabbabbabaaabaabbaabaa
|
||||||
|
abaaaabbaaaaaaabbaaabbbabbaaabaa
|
||||||
|
bbbbbbaababbababababbaba
|
||||||
|
bbaaabbaabbbabbbabbaabba
|
||||||
|
babaabbbaabaababaabaabba
|
||||||
|
ababbbabbabbbaaabababbab
|
||||||
|
bbaabbaaaaaaaaabbaabaaaa
|
||||||
|
abbbbbabbbbabaaaaaabbbbabbbbbbbabaabbbaaaababbab
|
||||||
|
bbbbaababaaabbabababaaba
|
||||||
|
babbabaababbaaabaababbaa
|
||||||
|
babbbaaaababaaababbbabaaabbbabaaabbbbbba
|
||||||
|
bbbaabaababbababbbabaabb
|
||||||
|
aababbbbabbabbbbababbbabbbabbababbababab
|
||||||
|
baaaabbbbaaabbabbaabaabaaababbaaaaaaaabbbaabbbaaaabaaabb
|
||||||
|
aaaaaaaaababbbbbbbbaaaaabababaaabbbbbaaa
|
||||||
|
aaaaabababbabaabbabbabaaaaaabaab
|
||||||
|
ababbbabbabbbaabbaaababb
|
||||||
|
abaaabbababaaaababbabbaaabaaabaa
|
||||||
|
babbabbbbabaaabbaabbbbaaabbbabaababbbbbbabaabbabaaabbbba
|
||||||
|
aaaaabbbabbabbbbbbaaaaaa
|
||||||
|
aaababbabbabaaabbabbabbb
|
||||||
|
babaabbbabbbabbbaabbbbbbbaabbaabaababbab
|
||||||
|
aaabbaabbaabbbbaaaaabbabbbaaaabbbaabababaaabbbabbababaaabbaababb
|
||||||
|
babbbbabababbabbbababbab
|
||||||
|
bababbbbbaabaaabaabaaababbaabaabaaaaaaabbbababaaaaabaaba
|
||||||
|
aaaaaaaabaaaabbbbbaaabaa
|
||||||
|
bbabbbbbaabaaaaaaaaaabaaabaabababbbbbbaaaaababbaaaababbb
|
||||||
|
aaabababaababbababbbbbaabbaabbba
|
||||||
|
baababababaaabbbbaaabbbb
|
||||||
|
ababbbabbaababbbbaaaaaababbbaabbaaaaabaabaabaaaa
|
||||||
|
babbaabbaabbaabbbaaaabbbababbbbbbabbbabbaaaababbbaaabaaaaababbaaaaababbbbbbbabbaaaababaa
|
||||||
|
aaaaaabbbbabaababbbaaababbababaa
|
||||||
|
babbbbaababbaabbabbbbaba
|
||||||
|
bbaabbaaaaaabbbbabababbbbbabbbbbbaaabaaaabbabbbabbabbaaaaaaababa
|
||||||
|
ababbbaababbbaaaaabaabaa
|
||||||
|
baaaabbbbbbbabbaabbabaaa
|
124
www/statics/aoc/2020/19_solution.rs
Normal file
124
www/statics/aoc/2020/19_solution.rs
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use crate::common::AdventOfCodeDay;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
pub struct Day19 {
|
||||||
|
rules: HashMap<u32, Rule>,
|
||||||
|
input: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
enum Rule {
|
||||||
|
RuleExpand(Vec<u32>),
|
||||||
|
RuleSplit(Vec<u32>, Vec<u32>),
|
||||||
|
RuleLiteral(char),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day19 {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let input_bytes = include_bytes!("../res/19_input.txt");
|
||||||
|
let input_str = String::from_utf8_lossy(input_bytes);
|
||||||
|
|
||||||
|
let rex_lines = Regex::new(r"(\r?\n){2}").unwrap();
|
||||||
|
let split = rex_lines.split(&input_str).collect::<Vec<&str>>();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
rules: split[0].lines().map(|p| Day19::parse_rule(String::from(p))).collect(),
|
||||||
|
input: split[1].lines().map(|p| String::from(p)).collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day19 {
|
||||||
|
fn parse_rule(input: String) -> (u32, Rule) {
|
||||||
|
lazy_static! {
|
||||||
|
static ref REX_EXPAND: Regex = Regex::new(r#"^(?P<id>[0-9]+):(?P<exp>( [0-9]+)+)$"#).unwrap();
|
||||||
|
static ref REX_SPLIT: Regex = Regex::new(r#"^(?P<id>[0-9]+):(?P<exp1>( [0-9]+)+) \|(?P<exp2>( [0-9]+)+)$"#).unwrap();
|
||||||
|
static ref REX_LITERAL: Regex = Regex::new(r#"^(?P<id>[0-9]+): "(?P<chr>[a-z])"$"#).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(cap) = REX_EXPAND.captures(&input) {
|
||||||
|
let id = cap.name("id").unwrap().as_str().parse::<u32>().unwrap();
|
||||||
|
let exp = cap.name("exp").unwrap().as_str().trim().split(' ').map(|p| p.parse::<u32>().unwrap()).collect::<Vec<u32>>();
|
||||||
|
|
||||||
|
return (id, Rule::RuleExpand(exp));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(cap) = REX_SPLIT.captures(&input) {
|
||||||
|
let id = cap.name("id").unwrap().as_str().parse::<u32>().unwrap();
|
||||||
|
let exp1 = cap.name("exp1").unwrap().as_str().trim().split(' ').map(|p| p.parse::<u32>().unwrap()).collect::<Vec<u32>>();
|
||||||
|
let exp2 = cap.name("exp2").unwrap().as_str().trim().split(' ').map(|p| p.parse::<u32>().unwrap()).collect::<Vec<u32>>();
|
||||||
|
|
||||||
|
return (id, Rule::RuleSplit(exp1, exp2));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(cap) = REX_LITERAL.captures(&input) {
|
||||||
|
let id = cap.name("id").unwrap().as_str().parse::<u32>().unwrap();
|
||||||
|
let chr = cap.name("chr").unwrap().as_str().chars().nth(0).unwrap();
|
||||||
|
|
||||||
|
return (id, Rule::RuleLiteral(chr));
|
||||||
|
}
|
||||||
|
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_rule(rules: &HashMap<u32, Rule>, str: Vec<char>, exp: Vec<u32>) -> bool {
|
||||||
|
|
||||||
|
if str.len() == 0 && exp.len() == 0 { return true; }
|
||||||
|
|
||||||
|
if str.len() == 0 || exp.len() == 0 { return false; }
|
||||||
|
|
||||||
|
let r = rules.get(&exp[0]).unwrap();
|
||||||
|
|
||||||
|
match r {
|
||||||
|
Rule::RuleLiteral(rchr) => {
|
||||||
|
if *rchr != str[0] { return false; }
|
||||||
|
let str_sub = str.iter().skip(1).map(|p| *p).collect::<Vec<char>>();
|
||||||
|
let exp_sub = exp.iter().skip(1).map(|p| *p).collect::<Vec<u32>>();
|
||||||
|
return Self::check_rule(rules, str_sub, exp_sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::RuleExpand(rexp) => {
|
||||||
|
let str_sub = str.clone();
|
||||||
|
let mut exp_sub = rexp.clone();
|
||||||
|
exp_sub.extend(exp.iter().skip(1).map(|p| *p));
|
||||||
|
return Self::check_rule(rules, str_sub, exp_sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
Rule::RuleSplit(rexp1, rexp2) => {
|
||||||
|
let str_sub1 = str.clone();
|
||||||
|
let mut exp_sub1 = rexp1.clone();
|
||||||
|
exp_sub1.extend(exp.iter().skip(1).map(|p| *p));
|
||||||
|
if Self::check_rule(rules, str_sub1, exp_sub1) { return true; }
|
||||||
|
|
||||||
|
let str_sub2 = str.clone();
|
||||||
|
let mut exp_sub2 = rexp2.clone();
|
||||||
|
exp_sub2.extend(exp.iter().skip(1).map(|p| *p));
|
||||||
|
if Self::check_rule(rules, str_sub2, exp_sub2) { return true; }
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AdventOfCodeDay for Day19 {
|
||||||
|
|
||||||
|
fn task_1(&self) -> String {
|
||||||
|
|
||||||
|
return self.input.iter().filter(|v| Day19::check_rule(&self.rules, v.chars().collect(), vec![0]) ).count().to_string();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn task_2(&self) -> String {
|
||||||
|
|
||||||
|
let mut rules = self.rules.clone();
|
||||||
|
|
||||||
|
rules.insert(8, Rule::RuleSplit(vec![42], vec![42, 8]));
|
||||||
|
rules.insert(11, Rule::RuleSplit(vec![42, 31], vec![42, 11, 31]));
|
||||||
|
|
||||||
|
return self.input.iter().filter(|v| Day19::check_rule(&rules, v.chars().collect(), vec![0]) ).count().to_string();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
263
www/statics/aoc/2020/20_challenge.txt
Normal file
263
www/statics/aoc/2020/20_challenge.txt
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
The high-speed train leaves the forest and quickly carries you south. You can even see a desert in the distance! Since you have some spare time, you might as well see if there was anything interesting in the image the Mythical Information Bureau satellite captured.
|
||||||
|
|
||||||
|
After decoding the satellite messages, you discover that the data actually contains many small images created by the satellite's camera array. The camera array consists of many cameras; rather than produce a single square image, they produce many smaller square image tiles that need to be reassembled back into a single image.
|
||||||
|
|
||||||
|
Each camera in the camera array returns a single monochrome image tile with a random unique ID number. The tiles (your puzzle input) arrived in a random order.
|
||||||
|
|
||||||
|
Worse yet, the camera array appears to be malfunctioning: each image tile has been rotated and flipped to a random orientation. Your first task is to reassemble the original image by orienting the tiles so they fit together.
|
||||||
|
|
||||||
|
To show how the tiles should be reassembled, each tile's image data includes a border that should line up exactly with its adjacent tiles. All tiles have this border, and the border lines up exactly when the tiles are both oriented correctly. Tiles at the edge of the image also have this border, but the outermost edges won't line up with any other tiles.
|
||||||
|
|
||||||
|
For example, suppose you have the following nine tiles:
|
||||||
|
|
||||||
|
Tile 2311:
|
||||||
|
..##.#..#.
|
||||||
|
##..#.....
|
||||||
|
#...##..#.
|
||||||
|
####.#...#
|
||||||
|
##.##.###.
|
||||||
|
##...#.###
|
||||||
|
.#.#.#..##
|
||||||
|
..#....#..
|
||||||
|
###...#.#.
|
||||||
|
..###..###
|
||||||
|
|
||||||
|
Tile 1951:
|
||||||
|
#.##...##.
|
||||||
|
#.####...#
|
||||||
|
.....#..##
|
||||||
|
#...######
|
||||||
|
.##.#....#
|
||||||
|
.###.#####
|
||||||
|
###.##.##.
|
||||||
|
.###....#.
|
||||||
|
..#.#..#.#
|
||||||
|
#...##.#..
|
||||||
|
|
||||||
|
Tile 1171:
|
||||||
|
####...##.
|
||||||
|
#..##.#..#
|
||||||
|
##.#..#.#.
|
||||||
|
.###.####.
|
||||||
|
..###.####
|
||||||
|
.##....##.
|
||||||
|
.#...####.
|
||||||
|
#.##.####.
|
||||||
|
####..#...
|
||||||
|
.....##...
|
||||||
|
|
||||||
|
Tile 1427:
|
||||||
|
###.##.#..
|
||||||
|
.#..#.##..
|
||||||
|
.#.##.#..#
|
||||||
|
#.#.#.##.#
|
||||||
|
....#...##
|
||||||
|
...##..##.
|
||||||
|
...#.#####
|
||||||
|
.#.####.#.
|
||||||
|
..#..###.#
|
||||||
|
..##.#..#.
|
||||||
|
|
||||||
|
Tile 1489:
|
||||||
|
##.#.#....
|
||||||
|
..##...#..
|
||||||
|
.##..##...
|
||||||
|
..#...#...
|
||||||
|
#####...#.
|
||||||
|
#..#.#.#.#
|
||||||
|
...#.#.#..
|
||||||
|
##.#...##.
|
||||||
|
..##.##.##
|
||||||
|
###.##.#..
|
||||||
|
|
||||||
|
Tile 2473:
|
||||||
|
#....####.
|
||||||
|
#..#.##...
|
||||||
|
#.##..#...
|
||||||
|
######.#.#
|
||||||
|
.#...#.#.#
|
||||||
|
.#########
|
||||||
|
.###.#..#.
|
||||||
|
########.#
|
||||||
|
##...##.#.
|
||||||
|
..###.#.#.
|
||||||
|
|
||||||
|
Tile 2971:
|
||||||
|
..#.#....#
|
||||||
|
#...###...
|
||||||
|
#.#.###...
|
||||||
|
##.##..#..
|
||||||
|
.#####..##
|
||||||
|
.#..####.#
|
||||||
|
#..#.#..#.
|
||||||
|
..####.###
|
||||||
|
..#.#.###.
|
||||||
|
...#.#.#.#
|
||||||
|
|
||||||
|
Tile 2729:
|
||||||
|
...#.#.#.#
|
||||||
|
####.#....
|
||||||
|
..#.#.....
|
||||||
|
....#..#.#
|
||||||
|
.##..##.#.
|
||||||
|
.#.####...
|
||||||
|
####.#.#..
|
||||||
|
##.####...
|
||||||
|
##..#.##..
|
||||||
|
#.##...##.
|
||||||
|
|
||||||
|
Tile 3079:
|
||||||
|
#.#.#####.
|
||||||
|
.#..######
|
||||||
|
..#.......
|
||||||
|
######....
|
||||||
|
####.#..#.
|
||||||
|
.#...#.##.
|
||||||
|
#.#####.##
|
||||||
|
..#.###...
|
||||||
|
..#.......
|
||||||
|
..#.###...
|
||||||
|
|
||||||
|
By rotating, flipping, and rearranging them, you can find a square arrangement that causes all adjacent borders to line up:
|
||||||
|
|
||||||
|
#...##.#.. ..###..### #.#.#####.
|
||||||
|
..#.#..#.# ###...#.#. .#..######
|
||||||
|
.###....#. ..#....#.. ..#.......
|
||||||
|
###.##.##. .#.#.#..## ######....
|
||||||
|
.###.##### ##...#.### ####.#..#.
|
||||||
|
.##.#....# ##.##.###. .#...#.##.
|
||||||
|
#...###### ####.#...# #.#####.##
|
||||||
|
.....#..## #...##..#. ..#.###...
|
||||||
|
#.####...# ##..#..... ..#.......
|
||||||
|
#.##...##. ..##.#..#. ..#.###...
|
||||||
|
|
||||||
|
#.##...##. ..##.#..#. ..#.###...
|
||||||
|
##..#.##.. ..#..###.# ##.##....#
|
||||||
|
##.####... .#.####.#. ..#.###..#
|
||||||
|
####.#.#.. ...#.##### ###.#..###
|
||||||
|
.#.####... ...##..##. .######.##
|
||||||
|
.##..##.#. ....#...## #.#.#.#...
|
||||||
|
....#..#.# #.#.#.##.# #.###.###.
|
||||||
|
..#.#..... .#.##.#..# #.###.##..
|
||||||
|
####.#.... .#..#.##.. .######...
|
||||||
|
...#.#.#.# ###.##.#.. .##...####
|
||||||
|
|
||||||
|
...#.#.#.# ###.##.#.. .##...####
|
||||||
|
..#.#.###. ..##.##.## #..#.##..#
|
||||||
|
..####.### ##.#...##. .#.#..#.##
|
||||||
|
#..#.#..#. ...#.#.#.. .####.###.
|
||||||
|
.#..####.# #..#.#.#.# ####.###..
|
||||||
|
.#####..## #####...#. .##....##.
|
||||||
|
##.##..#.. ..#...#... .####...#.
|
||||||
|
#.#.###... .##..##... .####.##.#
|
||||||
|
#...###... ..##...#.. ...#..####
|
||||||
|
..#.#....# ##.#.#.... ...##.....
|
||||||
|
|
||||||
|
For reference, the IDs of the above tiles are:
|
||||||
|
|
||||||
|
1951 2311 3079
|
||||||
|
2729 1427 2473
|
||||||
|
2971 1489 1171
|
||||||
|
|
||||||
|
To check that you've assembled the image correctly, multiply the IDs of the four corner tiles together. If you do this with the assembled tiles from the example above, you get 1951 * 3079 * 2971 * 1171 = 20899048083289.
|
||||||
|
|
||||||
|
Assemble the tiles into an image. What do you get if you multiply together the IDs of the four corner tiles?
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Now, you're ready to check the image for sea monsters.
|
||||||
|
|
||||||
|
The borders of each tile are not part of the actual image; start by removing them.
|
||||||
|
|
||||||
|
In the example above, the tiles become:
|
||||||
|
|
||||||
|
.#.#..#. ##...#.# #..#####
|
||||||
|
###....# .#....#. .#......
|
||||||
|
##.##.## #.#.#..# #####...
|
||||||
|
###.#### #...#.## ###.#..#
|
||||||
|
##.#.... #.##.### #...#.##
|
||||||
|
...##### ###.#... .#####.#
|
||||||
|
....#..# ...##..# .#.###..
|
||||||
|
.####... #..#.... .#......
|
||||||
|
|
||||||
|
#..#.##. .#..###. #.##....
|
||||||
|
#.####.. #.####.# .#.###..
|
||||||
|
###.#.#. ..#.#### ##.#..##
|
||||||
|
#.####.. ..##..## ######.#
|
||||||
|
##..##.# ...#...# .#.#.#..
|
||||||
|
...#..#. .#.#.##. .###.###
|
||||||
|
.#.#.... #.##.#.. .###.##.
|
||||||
|
###.#... #..#.##. ######..
|
||||||
|
|
||||||
|
.#.#.### .##.##.# ..#.##..
|
||||||
|
.####.## #.#...## #.#..#.#
|
||||||
|
..#.#..# ..#.#.#. ####.###
|
||||||
|
#..####. ..#.#.#. ###.###.
|
||||||
|
#####..# ####...# ##....##
|
||||||
|
#.##..#. .#...#.. ####...#
|
||||||
|
.#.###.. ##..##.. ####.##.
|
||||||
|
...###.. .##...#. ..#..###
|
||||||
|
|
||||||
|
Remove the gaps to form the actual image:
|
||||||
|
|
||||||
|
.#.#..#.##...#.##..#####
|
||||||
|
###....#.#....#..#......
|
||||||
|
##.##.###.#.#..######...
|
||||||
|
###.#####...#.#####.#..#
|
||||||
|
##.#....#.##.####...#.##
|
||||||
|
...########.#....#####.#
|
||||||
|
....#..#...##..#.#.###..
|
||||||
|
.####...#..#.....#......
|
||||||
|
#..#.##..#..###.#.##....
|
||||||
|
#.####..#.####.#.#.###..
|
||||||
|
###.#.#...#.######.#..##
|
||||||
|
#.####....##..########.#
|
||||||
|
##..##.#...#...#.#.#.#..
|
||||||
|
...#..#..#.#.##..###.###
|
||||||
|
.#.#....#.##.#...###.##.
|
||||||
|
###.#...#..#.##.######..
|
||||||
|
.#.#.###.##.##.#..#.##..
|
||||||
|
.####.###.#...###.#..#.#
|
||||||
|
..#.#..#..#.#.#.####.###
|
||||||
|
#..####...#.#.#.###.###.
|
||||||
|
#####..#####...###....##
|
||||||
|
#.##..#..#...#..####...#
|
||||||
|
.#.###..##..##..####.##.
|
||||||
|
...###...##...#...#..###
|
||||||
|
|
||||||
|
Now, you're ready to search for sea monsters! Because your image is monochrome, a sea monster will look like this:
|
||||||
|
|
||||||
|
#
|
||||||
|
# ## ## ###
|
||||||
|
# # # # # #
|
||||||
|
|
||||||
|
When looking for this pattern in the image, the spaces can be anything; only the # need to match. Also, you might need to rotate or flip your image before it's oriented correctly to find sea monsters. In the above image, after flipping and rotating it to the appropriate orientation, there are two sea monsters (marked with O):
|
||||||
|
|
||||||
|
.####...#####..#...###..
|
||||||
|
#####..#..#.#.####..#.#.
|
||||||
|
.#.#...#.###...#.##.O#..
|
||||||
|
#.O.##.OO#.#.OO.##.OOO##
|
||||||
|
..#O.#O#.O##O..O.#O##.##
|
||||||
|
...#.#..##.##...#..#..##
|
||||||
|
#.##.#..#.#..#..##.#.#..
|
||||||
|
.###.##.....#...###.#...
|
||||||
|
#.####.#.#....##.#..#.#.
|
||||||
|
##...#..#....#..#...####
|
||||||
|
..#.##...###..#.#####..#
|
||||||
|
....#.##.#.#####....#...
|
||||||
|
..##.##.###.....#.##..#.
|
||||||
|
#...#...###..####....##.
|
||||||
|
.#.##...#.##.#.#.###...#
|
||||||
|
#.###.#..####...##..#...
|
||||||
|
#.###...#.##...#.##O###.
|
||||||
|
.O##.#OO.###OO##..OOO##.
|
||||||
|
..O#.O..O..O.#O##O##.###
|
||||||
|
#.#..##.########..#..##.
|
||||||
|
#.#####..#.#...##..#....
|
||||||
|
#....##..#.#########..##
|
||||||
|
#...#.....#..##...###.##
|
||||||
|
#..###....##.#...##.##.#
|
||||||
|
|
||||||
|
Determine how rough the waters are in the sea monsters' habitat by counting the number of # that are not part of a sea monster. In the above example, the habitat's water roughness is 273.
|
||||||
|
|
||||||
|
How many # are not part of a sea monster?
|
1728
www/statics/aoc/2020/20_input.txt
Normal file
1728
www/statics/aoc/2020/20_input.txt
Normal file
File diff suppressed because it is too large
Load Diff
660
www/statics/aoc/2020/20_solution.rs
Normal file
660
www/statics/aoc/2020/20_solution.rs
Normal file
@ -0,0 +1,660 @@
|
|||||||
|
use crate::common::AdventOfCodeDay;
|
||||||
|
|
||||||
|
use regex::Regex;
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
use strum_macros::EnumIter;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, EnumIter, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
enum Compass { North, East, South, West }
|
||||||
|
|
||||||
|
impl Compass {
|
||||||
|
pub fn transform_back(&self, tf: Transform) -> (Self, bool) {
|
||||||
|
return match tf {
|
||||||
|
|
||||||
|
Transform::None => match self {
|
||||||
|
Compass::North => (Compass::North, false),
|
||||||
|
Compass::East => (Compass::East, false),
|
||||||
|
Compass::South => (Compass::South, false),
|
||||||
|
Compass::West => (Compass::West, false),
|
||||||
|
},
|
||||||
|
|
||||||
|
Transform::RotCW090 => match self {
|
||||||
|
Compass::North => (Compass::West, false),
|
||||||
|
Compass::East => (Compass::North, false),
|
||||||
|
Compass::South => (Compass::East, false),
|
||||||
|
Compass::West => (Compass::South, false),
|
||||||
|
},
|
||||||
|
|
||||||
|
Transform::RotCW180 => match self {
|
||||||
|
Compass::North => (Compass::South, false),
|
||||||
|
Compass::East => (Compass::West, false),
|
||||||
|
Compass::South => (Compass::North, false),
|
||||||
|
Compass::West => (Compass::East, false),
|
||||||
|
},
|
||||||
|
|
||||||
|
Transform::RotCW270 => match self {
|
||||||
|
Compass::North => (Compass::East, false),
|
||||||
|
Compass::East => (Compass::South, false),
|
||||||
|
Compass::South => (Compass::West, false),
|
||||||
|
Compass::West => (Compass::North, false),
|
||||||
|
},
|
||||||
|
|
||||||
|
Transform::Flipped => match self {
|
||||||
|
Compass::North => (Compass::West, true),
|
||||||
|
Compass::East => (Compass::South, true),
|
||||||
|
Compass::South => (Compass::East, true),
|
||||||
|
Compass::West => (Compass::North, true),
|
||||||
|
},
|
||||||
|
|
||||||
|
Transform::RotCW090Flipped => match self {
|
||||||
|
Compass::North => (Compass::North, true),
|
||||||
|
Compass::East => (Compass::West, true),
|
||||||
|
Compass::South => (Compass::South, true),
|
||||||
|
Compass::West => (Compass::East, true),
|
||||||
|
},
|
||||||
|
|
||||||
|
Transform::RotCW180Flipped => match self {
|
||||||
|
Compass::North => (Compass::East, true),
|
||||||
|
Compass::East => (Compass::North, true),
|
||||||
|
Compass::South => (Compass::West, true),
|
||||||
|
Compass::West => (Compass::South, true),
|
||||||
|
},
|
||||||
|
|
||||||
|
Transform::RotCW270Flipped => match self {
|
||||||
|
Compass::North => (Compass::South, true),
|
||||||
|
Compass::East => (Compass::East, true),
|
||||||
|
Compass::South => (Compass::North, true),
|
||||||
|
Compass::West => (Compass::West, true),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, EnumIter, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
enum Transform {
|
||||||
|
None,
|
||||||
|
RotCW090,
|
||||||
|
RotCW180,
|
||||||
|
RotCW270,
|
||||||
|
Flipped,
|
||||||
|
RotCW090Flipped,
|
||||||
|
RotCW180Flipped,
|
||||||
|
RotCW270Flipped,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Tile {
|
||||||
|
id: u32,
|
||||||
|
bitmap: [[bool;10];10],
|
||||||
|
sides: HashMap<(Compass, bool), (u32,u32)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Day20 {
|
||||||
|
input: [[Tile;12];12],
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_tile_array() -> [[Tile;12];12] {
|
||||||
|
let mut vec = Vec::<[Tile;12]>::with_capacity(12);
|
||||||
|
|
||||||
|
for _ in 0..12 {
|
||||||
|
let mut inner = Vec::<Tile>::with_capacity(12);
|
||||||
|
for _ in 0..12 {
|
||||||
|
inner.push(Tile{ id: 0, bitmap: [[false;10];10], sides: HashMap::with_capacity(4*2) });
|
||||||
|
}
|
||||||
|
vec.push(inner.try_into().unwrap_or_else(|_|panic!()));
|
||||||
|
}
|
||||||
|
return vec.try_into().unwrap_or_else(|_|panic!())
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day20 {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let input_bytes = include_bytes!("../res/20_input.txt");
|
||||||
|
let input_str = String::from_utf8_lossy(input_bytes);
|
||||||
|
|
||||||
|
let rex = Regex::new(r"Tile (?P<id>[0-9]+):\n(?P<bmp>([.#]{10}\n){10})").unwrap();
|
||||||
|
|
||||||
|
let mut tiles = new_tile_array();
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
for cap in rex.captures_iter(&input_str)
|
||||||
|
{
|
||||||
|
tiles[i/12][i%12].id = cap.name("id").unwrap().as_str().parse::<u32>().unwrap();
|
||||||
|
|
||||||
|
let raw = cap.name("bmp").unwrap().as_str().lines().map(|l| l.chars().collect::<Vec<char>>()).collect::<Vec<Vec<char>>>();
|
||||||
|
|
||||||
|
for y in 0..10 {
|
||||||
|
for x in 0..10 {
|
||||||
|
tiles[i/12][i%12].bitmap[y][x] = raw[y][x]=='#';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tiles[i/12][i%12].gen_cache();
|
||||||
|
|
||||||
|
i+=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Self {
|
||||||
|
input: tiles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Day20 {
|
||||||
|
|
||||||
|
fn format_ids(tiles: &[[Tile;12];12]) -> String {
|
||||||
|
let mut r = String::new();
|
||||||
|
for y in 0..12 {
|
||||||
|
for x in 0..12 {
|
||||||
|
let pad = format!(" {}", tiles[y][x].id);
|
||||||
|
r.push_str(&pad);
|
||||||
|
}
|
||||||
|
r.push('\n');
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn format_bitmaps(tiles: &[[Tile;12];12]) -> String {
|
||||||
|
let mut r = String::with_capacity(12*12*12*12 + 1000);
|
||||||
|
|
||||||
|
for y in 0..(12 * 11) {
|
||||||
|
for x in 0..(12 * 11) {
|
||||||
|
|
||||||
|
let gx = x / 11;
|
||||||
|
let gy = y / 11;
|
||||||
|
|
||||||
|
let ix = x % 11;
|
||||||
|
let iy = y % 11;
|
||||||
|
|
||||||
|
if ix==10 || iy == 10 { r.push(' '); continue; }
|
||||||
|
|
||||||
|
r.push(match tiles[gy][gx].bitmap[iy][ix] {
|
||||||
|
true => '#',
|
||||||
|
false => '.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
r.push('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn corner_to_transform_tl(tfs: Vec<(Compass, bool)>) -> Vec<Transform> {
|
||||||
|
|
||||||
|
let rtf = tfs.iter().map(|(c,_)| *c).collect::<Vec<Compass>>();
|
||||||
|
|
||||||
|
if rtf.contains(&Compass::West) && rtf.contains(&Compass::North) { return vec![Transform::RotCW180, Transform::RotCW180Flipped]; }
|
||||||
|
if rtf.contains(&Compass::North) && rtf.contains(&Compass::East) { return vec![Transform::RotCW270, Transform::RotCW270Flipped]; }
|
||||||
|
if rtf.contains(&Compass::East) && rtf.contains(&Compass::South) { return vec![Transform::None, Transform::Flipped]; }
|
||||||
|
if rtf.contains(&Compass::South) && rtf.contains(&Compass::West) { return vec![Transform::RotCW090, Transform::RotCW090Flipped]; }
|
||||||
|
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_valid_neigbour_horz(left: &(&Tile, Transform), right: &(&Tile, Transform)) -> bool {
|
||||||
|
let s1 = left.0.get_side_after_transform(Compass::East, left.1);
|
||||||
|
let s2 = right.0.get_side_after_transform(Compass::West, right.1);
|
||||||
|
|
||||||
|
return s1.0 == s2.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_valid_neigbour_vert(top: &(&Tile, Transform), bottom: &(&Tile, Transform)) -> bool {
|
||||||
|
let s1 = top.0.get_side_after_transform(Compass::South, top.1);
|
||||||
|
let s2 = bottom.0.get_side_after_transform(Compass::North, bottom.1);
|
||||||
|
|
||||||
|
return s1.0 == s2.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_valid_candidate(x: usize, y: usize, tile: &Tile, transform: Transform, map: &HashMap::<(usize, usize), Vec<(&Tile, Transform)>>) -> bool {
|
||||||
|
|
||||||
|
if x > 0 {
|
||||||
|
if !map.get(&(x-1, y)).unwrap().iter().any(|t| Self::is_valid_neigbour_horz(t, &(tile, transform))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if x < 11 {
|
||||||
|
if !map.get(&(x+1, y)).unwrap().iter().any(|t| Self::is_valid_neigbour_horz(&(tile, transform), t)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if y > 0 {
|
||||||
|
if !map.get(&(x, y-1)).unwrap().iter().any(|t| Self::is_valid_neigbour_vert(t, &(tile, transform))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if y < 11 {
|
||||||
|
if !map.get(&(x, y+1)).unwrap().iter().any(|t| Self::is_valid_neigbour_vert(&(tile, transform), t)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reconstruct(tiles: &Vec<&Tile>) -> [[Tile;12];12] {
|
||||||
|
|
||||||
|
let mut candidates = HashMap::<(usize, usize), Vec<(&Tile, Transform)>>::with_capacity(12*12);
|
||||||
|
for y in 0..12 {
|
||||||
|
for x in 0..12 {
|
||||||
|
candidates.insert((x,y), tiles.iter().flat_map(|tile| Transform::iter().map(move |tf| (*tile, tf))).collect());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let corners_tl = tiles.iter()
|
||||||
|
.map(|t| (t, t.matching_sides(&tiles)))
|
||||||
|
.filter(|(_,s)| s.len()==2)
|
||||||
|
.map(|(t,s)| (*t, Self::corner_to_transform_tl(s)))
|
||||||
|
.flat_map(|(t,s)| s.iter().map(|tf| (t, *tf)).collect::<Vec<(&Tile, Transform)>>() )
|
||||||
|
.collect::<Vec<(&Tile, Transform)>>();
|
||||||
|
|
||||||
|
let corner_tl = corners_tl.iter().skip(5).nth(0).unwrap();
|
||||||
|
|
||||||
|
verboseln!("Define [0,0] := ({}, {:?}):", corner_tl.0.id, corner_tl.1);
|
||||||
|
verboseln!("{}", corner_tl.0.transform(corner_tl.1).format_bitmap());
|
||||||
|
|
||||||
|
candidates.insert((0, 0), vec![*corner_tl]);
|
||||||
|
|
||||||
|
for yy in 0..12 {
|
||||||
|
for xx in 0..12 {
|
||||||
|
if xx== 0 && yy == 0 { continue; }
|
||||||
|
let other = candidates.get_mut(&(xx,yy)).unwrap();
|
||||||
|
other.retain(|p| p.0.id != corner_tl.0.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
|
|
||||||
|
let mut ok = 0;
|
||||||
|
for y in 0..12 {
|
||||||
|
for x in 0..12 {
|
||||||
|
let cand = candidates.get(&(x,y)).unwrap();
|
||||||
|
if cand.len() == 1 { ok+=1; continue; }
|
||||||
|
|
||||||
|
let oldlen = cand.len();
|
||||||
|
|
||||||
|
let mut cand_clone = cand.clone();
|
||||||
|
cand_clone.retain(|(tile, tf)| Day20::is_valid_candidate(x, y, tile, *tf, &candidates));
|
||||||
|
|
||||||
|
|
||||||
|
if cand_clone.len() == 0 {
|
||||||
|
verboseln!("Reduced [{},{}] from {} to {} candidates", x, y, oldlen, cand_clone.len());
|
||||||
|
panic!("No more candidates after [is_valid_candidate]");
|
||||||
|
}
|
||||||
|
else if oldlen != cand_clone.len() {
|
||||||
|
if cand_clone.len() == 1 {
|
||||||
|
verboseln!(" > Found tile for [{},{}] from {} candidates := ({}, {:?}):", x, y, oldlen, cand_clone[0].0.id, cand_clone[0].1);
|
||||||
|
verboseln!("{}", cand_clone[0].0.transform(cand_clone[0].1).format_bitmap());
|
||||||
|
verboseln!();
|
||||||
|
} else {
|
||||||
|
verboseln!("Reduced [{},{}] from {} to {} candidates", x, y, oldlen, cand_clone.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
if cand_clone.len() == 1 {
|
||||||
|
for yy in 0..12 {
|
||||||
|
for xx in 0..12 {
|
||||||
|
if x==xx && y==yy { continue; }
|
||||||
|
|
||||||
|
let other = candidates.get_mut(&(xx,yy)).unwrap();
|
||||||
|
|
||||||
|
let other_oldlen = other.len();
|
||||||
|
other.retain(|p| p.0.id != cand_clone[0].0.id);
|
||||||
|
|
||||||
|
if other_oldlen != other.len() {
|
||||||
|
verboseln!("Auto-force reduced [{},{}] from {} to {} candidates (triggered by [{},{}])", xx, yy, other_oldlen, other.len(), x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if other.len() == 0 { panic!("No more candidates after [retain] in [{},{}]", xx, yy); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates.insert((x, y), cand_clone);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
verboseln!("No changes on [{},{}] ({} candidates)", x, y, oldlen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok == 12*12 { break; }
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut tiles = new_tile_array();
|
||||||
|
for y in 0..12 {
|
||||||
|
for x in 0..12 {
|
||||||
|
tiles[y][x].id = candidates[&(x,y)][0].0.id;
|
||||||
|
tiles[y][x].bitmap = Tile::apply_transform_10(&candidates[&(x,y)][0].0.bitmap, candidates[&(x,y)][0].1);
|
||||||
|
tiles[y][x].gen_cache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find_monsters(sea: &[[bool;8*12];8*12], str_blueprint: String) -> (Vec<(usize, usize)>, Vec<(usize, usize)>) {
|
||||||
|
let bp_width = str_blueprint.lines().nth(0).unwrap().len();
|
||||||
|
let bp_height = str_blueprint.lines().count();
|
||||||
|
let blueprint = str_blueprint
|
||||||
|
.lines()
|
||||||
|
.enumerate()
|
||||||
|
.flat_map(|(y,l)| l.chars().enumerate().filter(|(_,v)| *v=='#').map(move |(x,_)| (x,y)))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
verboseln!("Monster: {:?}", blueprint);
|
||||||
|
|
||||||
|
let mut r = Vec::new();
|
||||||
|
|
||||||
|
for y in 0..(8*12-bp_height) {
|
||||||
|
for x in 0..(8*12-bp_width) {
|
||||||
|
if blueprint.iter().all(|(dx,dy)| sea[y + *dy][x + *dx]) { r.push((x, y)); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mk = r.iter()
|
||||||
|
.flat_map(|(sx,sy)| blueprint.iter().map(move |(dx,dy)| (*sx+*dx, *sy+*dy)))
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
|
.iter()
|
||||||
|
.map(|p|*p)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
return (r, mk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Tile {
|
||||||
|
fn format_bitmap(&self) -> String {
|
||||||
|
let mut r = String::with_capacity(10*11);
|
||||||
|
|
||||||
|
for y in 0..10 {
|
||||||
|
for x in 0..10 {
|
||||||
|
r.push(match self.bitmap[y][x] {
|
||||||
|
true => '#',
|
||||||
|
false => '.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
r.push('\n');
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn transform(&self, tf: Transform) -> Self {
|
||||||
|
let mut r = Self {
|
||||||
|
id: self.id,
|
||||||
|
bitmap: Self::apply_transform_10(&self.bitmap, tf),
|
||||||
|
sides: HashMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
r.gen_cache();
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply_transform_10(src: &[[bool;10];10], tf: Transform) -> [[bool;10];10] {
|
||||||
|
let mut r = [[false;10];10];
|
||||||
|
|
||||||
|
for src_y in 0..10 {
|
||||||
|
for src_x in 0..10 {
|
||||||
|
|
||||||
|
let dst_x: usize;
|
||||||
|
let dst_y: usize;
|
||||||
|
|
||||||
|
match tf {
|
||||||
|
Transform::None => { dst_x = 0 + src_x; dst_y = 0 + src_y; },
|
||||||
|
Transform::RotCW090 => { dst_x = 9 - src_y; dst_y = 0 + src_x; },
|
||||||
|
Transform::RotCW180 => { dst_x = 9 - src_x; dst_y = 9 - src_y; },
|
||||||
|
Transform::RotCW270 => { dst_x = 0 + src_y; dst_y = 9 - src_x; },
|
||||||
|
|
||||||
|
Transform::Flipped => { dst_x = 0 + src_y; dst_y = 0 + src_x; },
|
||||||
|
Transform::RotCW090Flipped => { dst_x = 9 - src_x; dst_y = 0 + src_y; },
|
||||||
|
Transform::RotCW180Flipped => { dst_x = 9 - src_y; dst_y = 9 - src_x; },
|
||||||
|
Transform::RotCW270Flipped => { dst_x = 0 + src_x; dst_y = 9 - src_y; },
|
||||||
|
};
|
||||||
|
|
||||||
|
r[dst_y][dst_x] = src[src_y][src_x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply_transform_96(src: &[[bool;8*12];8*12], tf: Transform) -> [[bool;8*12];8*12] {
|
||||||
|
let mut r = [[false;8*12];8*12];
|
||||||
|
|
||||||
|
for src_y in 0..(8*12) {
|
||||||
|
for src_x in 0..(8*12) {
|
||||||
|
|
||||||
|
let dst_x: usize;
|
||||||
|
let dst_y: usize;
|
||||||
|
|
||||||
|
match tf {
|
||||||
|
Transform::None => { dst_x = 0 + src_x; dst_y = 0 + src_y; },
|
||||||
|
Transform::RotCW090 => { dst_x = 95 - src_y; dst_y = 0 + src_x; },
|
||||||
|
Transform::RotCW180 => { dst_x = 95 - src_x; dst_y = 95 - src_y; },
|
||||||
|
Transform::RotCW270 => { dst_x = 0 + src_y; dst_y = 95 - src_x; },
|
||||||
|
|
||||||
|
Transform::Flipped => { dst_x = 0 + src_y; dst_y = 0 + src_x; },
|
||||||
|
Transform::RotCW090Flipped => { dst_x = 95 - src_x; dst_y = 0 + src_y; },
|
||||||
|
Transform::RotCW180Flipped => { dst_x = 95 - src_y; dst_y = 95 - src_x; },
|
||||||
|
Transform::RotCW270Flipped => { dst_x = 0 + src_x; dst_y = 95 - src_y; },
|
||||||
|
};
|
||||||
|
|
||||||
|
r[dst_y][dst_x] = src[src_y][src_x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn side_to_int(s: &[bool;10]) -> (u32,u32) {
|
||||||
|
let mut u1=0;
|
||||||
|
for i in 0..10 {
|
||||||
|
u1 *= 2;
|
||||||
|
if s[i] { u1 += 1; }
|
||||||
|
}
|
||||||
|
let mut u2=0;
|
||||||
|
for i in 0..10 {
|
||||||
|
u2 *= 2;
|
||||||
|
if s[9-i] { u2 += 1; }
|
||||||
|
}
|
||||||
|
return (u1,u2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_side(&self, d: Compass, flipped: bool) -> (u32,u32) {
|
||||||
|
return *self.sides.get(&(d,flipped)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_side_after_transform(&self, d: Compass, tf: Transform) -> (u32,u32) {
|
||||||
|
return *self.sides.get(&d.transform_back(tf)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn calc_side(&self, d: Compass, flipped: bool) -> [bool;10] {
|
||||||
|
let mut r = [false;10];
|
||||||
|
|
||||||
|
match flipped {
|
||||||
|
false =>
|
||||||
|
{
|
||||||
|
match d {
|
||||||
|
Compass::North =>
|
||||||
|
{
|
||||||
|
for i in 0..10 { r[i] = self.bitmap[0][i]; }
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
Compass::East =>
|
||||||
|
{
|
||||||
|
for i in 0..10 { r[i] = self.bitmap[i][9]; }
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
Compass::South =>
|
||||||
|
{
|
||||||
|
for i in 0..10 { r[i] = self.bitmap[9][9-i]; }
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
Compass::West =>
|
||||||
|
{
|
||||||
|
for i in 0..10 { r[i] = self.bitmap[9-i][0]; }
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true =>
|
||||||
|
{
|
||||||
|
match d {
|
||||||
|
Compass::North =>
|
||||||
|
{
|
||||||
|
for i in 0..10 { r[i] = self.bitmap[0][9-i]; }
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
Compass::East =>
|
||||||
|
{
|
||||||
|
for i in 0..10 { r[i] = self.bitmap[9-i][9]; }
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
Compass::South =>
|
||||||
|
{
|
||||||
|
for i in 0..10 { r[i] = self.bitmap[9][i]; }
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
Compass::West =>
|
||||||
|
{
|
||||||
|
for i in 0..10 { r[i] = self.bitmap[i][0]; }
|
||||||
|
return r;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn matching_sides(&self, tiles: &Vec<&Tile>) -> Vec<(Compass, bool)> {
|
||||||
|
|
||||||
|
let mut r = Vec::<(Compass, bool)>::new();
|
||||||
|
|
||||||
|
for d in Compass::iter() {
|
||||||
|
for f in &[true, false] {
|
||||||
|
let side = self.get_side(d, *f);
|
||||||
|
|
||||||
|
let mut c = 0;
|
||||||
|
for tile in tiles.iter().filter(|t| t.id != self.id) {
|
||||||
|
for d2 in Compass::iter() {
|
||||||
|
if side.0 == tile.get_side(d2, true).0 {
|
||||||
|
c+=1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if c > 0 {
|
||||||
|
r.push((d, *f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gen_cache(&mut self) {
|
||||||
|
for c in Compass::iter() {
|
||||||
|
self.sides.insert((c, false), Self::side_to_int(&self.calc_side(c, false)));
|
||||||
|
self.sides.insert((c, true), Self::side_to_int(&self.calc_side(c, true)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AdventOfCodeDay for Day20 {
|
||||||
|
|
||||||
|
fn task_1(&self) -> String {
|
||||||
|
|
||||||
|
verboseln!("{}", Day20::format_ids(&self.input));
|
||||||
|
verboseln!("{}", Day20::format_bitmaps(&self.input));
|
||||||
|
|
||||||
|
let tiles = self.input.iter().flat_map(|p| p.iter()).collect::<Vec<&Tile>>();
|
||||||
|
|
||||||
|
if is_verbose!() {
|
||||||
|
for t in tiles.iter().filter(|t| t.matching_sides(&tiles).len() == 2) {
|
||||||
|
verboseln!("{}", t.format_bitmap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tiles.iter().filter(|t| t.matching_sides(&tiles).len() == 2).map(|p| p.id as u128).product::<u128>().to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn task_2(&self) -> String {
|
||||||
|
let tiles = self.input.iter().flat_map(|p| p.iter()).collect::<Vec<&Tile>>();
|
||||||
|
|
||||||
|
let bitmap_r = Day20::reconstruct(&tiles);
|
||||||
|
|
||||||
|
verboseln!("Reconstructed:");
|
||||||
|
verboseln!("{}", Day20::format_bitmaps(&bitmap_r));
|
||||||
|
|
||||||
|
let mut bitmap_full: [[bool;8*12];8*12] = [[false;8*12];8*12];
|
||||||
|
for gy in 0..12 {
|
||||||
|
for gx in 0..12 {
|
||||||
|
for iy in 1..9 {
|
||||||
|
for ix in 1..9 {
|
||||||
|
bitmap_full[gy*8+iy-1][gx*8+ix-1] = bitmap_r[gy][gx].bitmap[iy][ix];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_verbose!() {
|
||||||
|
verboseln!("Raw:");
|
||||||
|
let mut ostr = String::with_capacity(8*12*8*12);
|
||||||
|
for y in 0..(8*12) {
|
||||||
|
for x in 0..(8*12) {
|
||||||
|
ostr.push(if bitmap_full[y][x] {'#'} else {'.'})
|
||||||
|
}
|
||||||
|
ostr.push('\n');
|
||||||
|
}
|
||||||
|
verboseln!("{}", ostr);
|
||||||
|
}
|
||||||
|
|
||||||
|
let monster_blueprint = "".to_owned() +
|
||||||
|
" # " + "\n" +
|
||||||
|
"# ## ## ###" + "\n" +
|
||||||
|
" # # # # # # ";
|
||||||
|
|
||||||
|
let mut monster_parts = Vec::new();
|
||||||
|
let mut monster_bitmap: [[bool;8*12];8*12] = [[false;8*12];8*12];
|
||||||
|
for tf in Transform::iter() {
|
||||||
|
|
||||||
|
let bitmap_tf = Tile::apply_transform_96(&bitmap_full, tf);
|
||||||
|
|
||||||
|
let (monsters, markers) = Day20::find_monsters(&bitmap_tf, monster_blueprint.clone());
|
||||||
|
verboseln!("Monsters in {:?}: {:?}", tf, monsters);
|
||||||
|
|
||||||
|
if !monsters.is_empty() {
|
||||||
|
monster_parts = markers;
|
||||||
|
monster_bitmap = bitmap_tf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut roughness = 0;
|
||||||
|
for x in 0..(8*12) {
|
||||||
|
for y in 0..(8*12) {
|
||||||
|
if monster_bitmap[y][x] && !monster_parts.contains(&(x,y)) { roughness += 1; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_verbose!() {
|
||||||
|
verboseln!("Analyzed:");
|
||||||
|
let mut ostr = String::with_capacity(8*12*8*12);
|
||||||
|
for y in 0..(8*12) {
|
||||||
|
for x in 0..(8*12) {
|
||||||
|
if monster_parts.contains(&(x,y)) {
|
||||||
|
ostr.push('O')
|
||||||
|
} else {
|
||||||
|
ostr.push(if monster_bitmap[y][x] {'#'} else {'.'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ostr.push('\n');
|
||||||
|
}
|
||||||
|
verboseln!("{}", ostr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return roughness.to_string();
|
||||||
|
}
|
||||||
|
}
|
@ -88,11 +88,11 @@ return
|
|||||||
['day' => 13, 'parts' => 2, 'title' => 'Shuttle Search', 'language' => 'rust', 'solutions' => ['1915', '294354277694107'] ],
|
['day' => 13, 'parts' => 2, 'title' => 'Shuttle Search', 'language' => 'rust', 'solutions' => ['1915', '294354277694107'] ],
|
||||||
['day' => 14, 'parts' => 2, 'title' => 'Docking Data', 'language' => 'rust', 'solutions' => ['12408060320841', '4466434626828'] ],
|
['day' => 14, 'parts' => 2, 'title' => 'Docking Data', 'language' => 'rust', 'solutions' => ['12408060320841', '4466434626828'] ],
|
||||||
['day' => 15, 'parts' => 2, 'title' => 'Rambunctious Recitation', 'language' => 'rust', 'solutions' => ['273', '47205'] ],
|
['day' => 15, 'parts' => 2, 'title' => 'Rambunctious Recitation', 'language' => 'rust', 'solutions' => ['273', '47205'] ],
|
||||||
//['day' => 16, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
['day' => 16, 'parts' => 2, 'title' => 'Ticket Translation', 'language' => 'rust', 'solutions' => ['29019', '517827547723'] ],
|
||||||
//['day' => 17, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
['day' => 17, 'parts' => 2, 'title' => 'Conway Cubes', 'language' => 'rust', 'solutions' => ['276', '2136'] ],
|
||||||
//['day' => 18, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
['day' => 18, 'parts' => 2, 'title' => 'Operation Order', 'language' => 'rust', 'solutions' => ['75592527415659', '360029542265462'] ],
|
||||||
//['day' => 19, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
['day' => 19, 'parts' => 2, 'title' => 'Monster Messages', 'language' => 'rust', 'solutions' => ['142', '294'] ],
|
||||||
//['day' => 20, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
['day' => 20, 'parts' => 2, 'title' => 'Jurassic Jigsaw', 'language' => 'rust', 'solutions' => ['64802175715999', '2146'] ],
|
||||||
//['day' => 21, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
//['day' => 21, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
||||||
//['day' => 22, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
//['day' => 22, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
||||||
//['day' => 23, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
//['day' => 23, 'parts' => 2, 'title' => '', 'language' => 'rust', 'solutions' => [] ],
|
||||||
|
@ -16,4 +16,6 @@ Usage:
|
|||||||
Options:
|
Options:
|
||||||
-h --help
|
-h --help
|
||||||
-b --benchmark
|
-b --benchmark
|
||||||
|
-v --verbose
|
||||||
|
-t --time
|
||||||
~~~
|
~~~
|
||||||
|
Loading…
Reference in New Issue
Block a user