Day 16...in Go this time!
This commit is contained in:
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/main.go",
|
||||
"env": {},
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
}
|
263
16input.txt
Normal file
263
16input.txt
Normal file
@ -0,0 +1,263 @@
|
||||
departure location: 49-920 or 932-950
|
||||
departure station: 28-106 or 130-969
|
||||
departure platform: 47-633 or 646-950
|
||||
departure track: 41-839 or 851-967
|
||||
departure date: 30-71 or 88-966
|
||||
departure time: 38-532 or 549-953
|
||||
arrival location: 38-326 or 341-968
|
||||
arrival station: 27-809 or 834-960
|
||||
arrival platform: 29-314 or 322-949
|
||||
arrival track: 26-358 or 368-966
|
||||
class: 34-647 or 667-951
|
||||
duration: 39-771 or 785-958
|
||||
price: 43-275 or 286-960
|
||||
route: 28-235 or 260-949
|
||||
row: 48-373 or 392-962
|
||||
seat: 35-147 or 172-953
|
||||
train: 37-861 or 885-961
|
||||
type: 38-473 or 483-961
|
||||
wagon: 49-221 or 228-973
|
||||
zone: 46-293 or 307-967
|
||||
|
||||
your ticket:
|
||||
101,179,193,103,53,89,181,139,137,97,61,71,197,59,67,173,199,211,191,131
|
||||
|
||||
nearby tickets:
|
||||
337,687,607,98,229,737,512,521,896,93,341,488,511,550,53,907,888,198,935,767
|
||||
506,605,103,683,788,899,101,551,420,947,944,805,495,858,942,980,687,232,145,765
|
||||
787,456,807,624,554,260,458,503,682,907,460,697,348,342,343,917,460,475,528,203
|
||||
613,944,732,939,417,585,520,585,680,260,611,912,367,573,628,802,905,741,421,66
|
||||
407,614,691,504,209,323,507,224,721,916,202,180,679,692,731,508,894,889,263,232
|
||||
346,591,998,267,904,713,343,443,583,569,100,585,422,509,62,728,907,451,567,176
|
||||
342,470,760,622,60,801,519,911,200,907,225,593,485,490,266,452,141,855,136,937
|
||||
129,439,195,947,941,324,272,101,60,94,522,351,68,630,357,264,344,93,209,612
|
||||
517,354,89,599,911,233,422,767,466,220,277,67,711,220,189,796,697,745,612,836
|
||||
611,231,449,265,497,906,591,551,570,197,702,231,161,556,173,104,501,891,555,397
|
||||
916,618,410,218,736,592,857,500,424,889,502,760,387,525,760,807,885,911,353,59
|
||||
459,290,191,471,174,945,934,583,748,357,291,841,195,138,620,808,461,587,670,851
|
||||
343,147,220,706,458,316,595,687,292,230,68,619,893,421,629,508,178,103,685,699
|
||||
142,734,221,269,646,624,730,347,355,469,451,544,793,273,260,685,219,207,405,354
|
||||
592,230,531,914,679,415,210,106,517,669,679,424,282,53,350,313,211,215,529,804
|
||||
731,494,104,752,994,839,208,617,626,738,702,51,670,583,700,673,897,515,190,574
|
||||
717,851,461,141,54,626,937,445,599,906,764,999,67,939,889,716,575,913,502,945
|
||||
157,422,622,797,904,210,457,457,217,436,450,293,185,503,447,763,734,493,486,807
|
||||
625,315,902,895,614,523,738,626,788,861,509,897,184,550,103,180,510,484,945,212
|
||||
853,325,194,309,573,101,490,347,271,100,317,670,448,50,473,580,229,898,804,469
|
||||
318,746,946,630,758,524,212,907,889,562,628,404,747,562,211,526,770,801,418,582
|
||||
350,796,755,54,105,552,181,440,220,369,635,858,739,626,674,769,218,737,805,138
|
||||
103,187,99,750,424,551,520,856,902,351,698,147,510,798,432,351,451,503,135,384
|
||||
465,421,624,400,893,506,485,235,228,893,447,162,740,175,614,137,729,680,463,210
|
||||
730,440,613,512,152,211,174,58,267,668,220,521,427,219,421,675,769,441,718,719
|
||||
427,401,12,93,573,91,460,104,393,500,564,198,613,468,936,725,504,496,501,501
|
||||
669,273,576,205,24,855,549,309,103,445,353,228,462,177,579,453,275,450,408,342
|
||||
851,373,185,445,719,949,920,792,325,944,161,397,202,723,433,566,550,310,462,271
|
||||
429,341,792,699,727,816,528,413,707,799,694,137,454,716,750,906,796,942,346,596
|
||||
798,626,858,365,584,206,185,312,720,61,576,599,263,260,632,698,560,692,263,348
|
||||
203,738,933,675,497,188,601,905,739,926,229,140,146,142,736,263,687,899,485,343
|
||||
428,198,751,436,106,235,597,504,667,647,90,432,903,555,627,485,987,573,805,677
|
||||
201,270,92,437,620,761,135,320,905,311,893,142,442,491,936,274,889,806,186,209
|
||||
742,147,944,572,407,185,615,96,771,462,646,437,938,628,152,453,737,617,461,516
|
||||
577,493,181,210,571,287,208,208,937,143,727,56,409,436,668,512,507,770,685,121
|
||||
751,313,746,785,403,917,527,115,676,714,556,676,856,458,55,206,890,272,497,600
|
||||
465,143,89,587,617,265,578,453,905,738,851,346,622,272,292,57,891,273,492,298
|
||||
415,441,92,230,678,345,89,584,948,75,503,53,705,456,95,511,402,895,531,694
|
||||
461,555,425,291,939,349,105,514,856,844,899,403,692,601,231,575,691,463,407,177
|
||||
569,785,905,200,88,613,268,160,269,94,70,763,212,401,229,326,405,326,715,676
|
||||
484,910,213,942,190,341,584,766,231,712,490,554,529,515,489,19,430,623,232,50
|
||||
571,130,130,314,191,920,483,976,592,93,468,807,698,408,417,143,262,510,373,696
|
||||
594,492,675,721,671,595,744,673,307,592,886,629,102,797,448,214,627,607,835,850
|
||||
211,592,102,944,395,600,501,375,946,745,907,182,568,788,483,464,915,403,88,514
|
||||
697,311,470,518,562,732,761,674,619,349,893,187,398,894,995,689,735,623,471,807
|
||||
62,280,462,341,176,682,423,172,58,669,518,699,566,705,519,681,308,400,629,945
|
||||
191,703,272,52,76,852,342,461,614,199,521,405,610,210,888,71,739,399,799,182
|
||||
834,175,727,459,509,677,739,394,712,771,936,348,183,855,675,592,475,454,412,698
|
||||
631,180,491,269,719,89,178,515,683,895,351,861,222,558,508,220,174,400,893,469
|
||||
310,788,593,681,756,490,450,91,217,895,532,376,682,742,560,897,430,765,730,441
|
||||
411,497,629,807,682,176,505,735,102,98,358,502,348,791,999,741,809,769,263,673
|
||||
187,202,357,854,373,582,193,496,738,509,339,106,858,211,681,131,518,667,530,521
|
||||
629,62,344,504,588,553,98,727,615,556,730,696,618,838,477,267,715,406,464,715
|
||||
100,852,626,803,69,408,742,811,613,105,260,178,206,613,309,759,462,499,949,853
|
||||
176,435,741,176,342,233,852,872,215,50,403,901,314,421,531,62,440,703,308,103
|
||||
858,530,791,519,935,709,576,470,383,753,401,396,718,144,307,211,51,839,680,92
|
||||
627,201,851,173,674,404,10,703,668,235,564,266,269,358,857,683,581,88,753,89
|
||||
70,224,174,756,215,699,693,104,432,65,557,555,854,707,806,911,352,208,54,894
|
||||
225,181,549,181,447,192,948,442,512,350,611,323,918,605,50,528,443,890,608,406
|
||||
935,350,211,839,892,403,358,931,179,795,458,570,619,144,717,891,229,425,890,728
|
||||
53,408,461,469,861,510,578,363,181,735,465,196,599,573,762,551,759,803,573,586
|
||||
291,106,919,506,472,710,522,551,189,493,90,365,855,489,204,574,578,857,554,94
|
||||
749,769,490,98,180,403,278,185,504,894,218,602,906,138,945,58,713,910,289,762
|
||||
207,418,611,350,825,761,402,176,632,578,486,789,106,624,453,178,408,417,594,607
|
||||
896,611,903,51,563,634,710,914,134,885,411,215,756,769,940,183,598,308,449,53
|
||||
792,392,891,143,579,58,493,612,158,606,565,793,180,102,503,392,677,891,174,709
|
||||
762,229,278,769,100,737,92,454,96,670,510,209,888,142,218,451,178,733,434,727
|
||||
142,448,198,511,723,494,131,515,472,274,947,462,336,439,373,349,308,178,313,767
|
||||
490,511,271,897,598,100,449,895,454,896,459,563,583,588,737,860,20,499,441,726
|
||||
562,465,903,408,451,750,625,300,808,592,602,509,352,699,211,529,292,689,210,582
|
||||
607,677,440,209,839,672,460,283,940,229,198,685,95,192,459,526,139,183,603,350
|
||||
172,493,101,746,893,55,616,906,740,731,705,284,493,672,908,235,88,464,96,904
|
||||
306,502,448,568,94,809,792,373,267,673,575,453,942,787,420,891,531,622,887,425
|
||||
212,894,444,808,67,688,177,549,496,24,69,273,590,173,515,729,343,853,438,674
|
||||
895,574,646,838,203,789,686,373,260,590,272,431,726,919,410,5,455,557,451,630
|
||||
598,64,768,95,219,613,411,570,932,680,299,434,736,439,671,892,577,888,275,324
|
||||
172,420,104,98,343,848,343,484,405,610,559,684,906,199,210,179,606,592,106,473
|
||||
721,433,768,686,943,594,942,396,142,53,713,400,683,438,892,69,463,106,478,633
|
||||
807,688,66,914,751,154,704,271,679,177,807,674,936,687,737,589,179,448,855,574
|
||||
627,221,216,405,18,802,620,208,701,712,620,217,372,66,890,92,405,95,369,527
|
||||
101,447,318,647,835,190,680,680,896,750,908,600,723,938,200,501,785,785,441,703
|
||||
900,235,860,703,186,413,947,477,592,98,356,101,898,714,563,948,210,229,587,326
|
||||
706,519,235,523,177,192,175,581,398,341,326,3,515,933,693,398,631,726,755,599
|
||||
452,351,368,265,788,593,325,394,738,285,803,558,504,737,855,439,485,919,731,133
|
||||
851,347,103,765,205,604,600,684,358,717,916,947,262,311,343,490,606,576,747,80
|
||||
685,743,941,578,944,526,213,890,574,881,917,788,404,192,723,493,906,561,514,355
|
||||
694,426,345,726,393,706,496,607,416,97,553,101,798,804,264,610,370,714,835,166
|
||||
735,587,322,395,917,755,336,186,742,590,261,739,794,793,712,92,682,701,712,58
|
||||
791,131,944,767,367,62,633,505,789,796,290,553,51,501,755,392,718,560,104,458
|
||||
633,349,915,398,67,602,69,204,216,745,714,120,368,690,601,561,717,677,272,189
|
||||
627,768,385,89,619,502,834,291,807,551,674,423,573,761,913,439,627,211,408,405
|
||||
462,750,53,615,229,554,418,272,739,175,269,530,829,670,745,358,919,556,945,632
|
||||
467,693,751,750,682,173,264,334,614,770,203,556,803,745,172,207,835,184,408,393
|
||||
911,179,322,430,697,626,582,934,95,783,532,487,325,698,808,496,263,800,802,914
|
||||
925,402,793,676,709,606,601,948,466,218,457,577,599,785,393,323,133,177,421,518
|
||||
292,551,838,562,913,748,348,792,507,519,606,697,693,854,551,526,179,604,343,997
|
||||
176,599,613,902,203,428,595,217,344,423,312,888,208,469,68,437,898,756,511,477
|
||||
621,628,941,157,793,556,745,622,714,621,633,792,519,620,716,50,229,508,65,799
|
||||
631,309,324,185,370,439,461,103,460,354,608,318,69,529,485,515,415,69,183,668
|
||||
499,679,183,198,468,232,788,511,97,789,392,935,78,89,203,516,355,709,58,397
|
||||
398,897,503,697,800,837,680,613,671,649,196,97,894,554,264,355,70,429,682,218
|
||||
454,450,487,572,860,985,631,215,793,710,796,594,890,726,628,137,194,791,373,176
|
||||
695,751,902,904,797,602,179,96,343,482,740,512,610,502,607,392,595,190,272,192
|
||||
14,212,763,584,496,767,462,197,943,578,697,53,707,408,618,834,399,702,401,311
|
||||
430,452,520,419,263,83,808,350,613,230,323,521,99,739,287,920,515,761,859,449
|
||||
722,527,144,572,55,103,754,527,182,562,792,571,715,143,194,562,4,63,622,229
|
||||
770,144,445,809,106,902,518,500,368,601,901,980,465,266,798,449,628,450,799,101
|
||||
733,61,626,670,468,532,478,684,504,173,136,700,409,566,890,900,443,914,510,552
|
||||
853,583,351,601,266,193,287,341,718,854,845,445,175,914,447,585,132,614,312,727
|
||||
196,274,908,22,451,768,905,918,915,746,582,69,260,722,697,674,604,910,596,61
|
||||
173,532,313,610,462,834,134,286,887,111,404,947,440,725,415,739,900,695,557,624
|
||||
323,54,735,700,224,563,771,734,859,939,712,496,506,730,405,724,199,760,447,314
|
||||
495,613,671,342,949,889,855,906,476,798,743,180,448,605,886,488,913,354,185,933
|
||||
836,496,563,54,391,448,204,271,567,322,484,401,486,917,490,570,196,466,938,730
|
||||
834,692,50,736,195,593,403,791,906,461,581,521,479,916,484,786,229,622,516,731
|
||||
674,235,308,673,324,106,681,620,428,96,732,644,751,310,424,718,786,726,687,53
|
||||
618,354,104,669,147,981,510,527,68,682,671,220,51,692,518,851,433,59,608,370
|
||||
528,758,738,194,474,91,572,59,770,899,502,761,601,342,355,681,561,324,444,751
|
||||
176,802,688,432,414,95,269,66,286,214,499,597,768,629,284,911,489,234,180,235
|
||||
949,526,63,222,940,98,908,753,886,580,504,942,947,707,763,500,609,934,793,939
|
||||
142,598,395,610,562,181,632,132,981,796,272,697,446,861,550,853,761,88,912,190
|
||||
501,837,938,203,807,272,134,232,851,644,503,549,557,286,694,887,422,792,622,677
|
||||
593,261,422,595,603,513,369,522,405,816,433,859,50,67,209,712,606,623,786,204
|
||||
459,932,589,499,333,566,235,235,755,890,441,104,741,412,718,684,618,219,186,352
|
||||
668,520,475,67,413,631,188,324,556,627,579,741,102,506,597,100,936,611,678,768
|
||||
54,745,498,941,217,214,169,523,934,350,453,606,757,439,50,407,140,918,273,233
|
||||
174,88,618,91,741,673,757,891,529,380,431,749,632,465,683,580,797,757,462,455
|
||||
97,722,99,580,448,104,945,909,667,545,178,468,462,532,893,65,744,629,791,910
|
||||
854,609,483,554,317,568,184,860,789,131,913,699,180,147,519,136,528,729,582,633
|
||||
718,579,449,392,502,361,412,672,670,199,729,751,288,860,709,614,576,444,617,98
|
||||
493,496,682,599,309,175,145,22,565,413,917,861,851,408,175,756,434,630,901,348
|
||||
889,908,197,517,264,771,898,312,800,759,613,747,420,455,893,977,58,684,350,580
|
||||
792,615,261,268,371,728,447,537,589,566,671,88,597,426,307,760,93,855,626,917
|
||||
372,475,188,605,739,432,900,61,261,268,565,599,94,193,432,733,949,742,191,437
|
||||
91,68,60,751,218,106,369,794,131,707,95,528,792,203,232,233,730,139,334,369
|
||||
617,96,860,420,440,618,763,356,311,360,737,560,763,308,735,590,915,135,633,595
|
||||
558,694,768,99,179,690,89,573,585,599,268,404,611,719,987,487,104,631,713,835
|
||||
311,9,469,485,889,910,208,940,192,836,421,853,510,408,786,799,601,270,553,942
|
||||
855,633,940,350,395,743,761,67,910,686,412,289,602,64,809,791,383,523,53,496
|
||||
857,136,690,313,686,684,266,235,216,600,403,136,297,566,624,838,628,426,859,717
|
||||
788,760,177,186,422,214,265,210,464,911,208,131,288,746,683,271,734,197,916,222
|
||||
78,484,458,268,612,806,901,764,526,97,941,903,911,262,580,193,599,561,729,689
|
||||
629,498,289,465,553,920,326,997,466,358,557,569,207,519,771,519,908,139,261,216
|
||||
146,398,423,217,356,802,906,141,503,444,948,182,687,893,835,358,406,403,176,364
|
||||
794,463,901,791,761,70,93,557,529,140,916,831,196,130,205,100,196,678,468,275
|
||||
203,729,229,55,614,99,918,356,835,496,726,660,935,90,407,855,514,71,353,754
|
||||
715,65,714,630,747,579,770,625,741,613,481,448,859,519,453,597,209,945,933,673
|
||||
822,347,459,513,492,915,532,746,946,273,612,677,888,704,916,501,724,404,413,582
|
||||
263,267,266,903,403,190,623,83,590,467,681,207,566,587,708,600,903,893,803,588
|
||||
621,729,573,886,899,450,391,747,58,443,739,619,630,943,352,585,217,528,669,722
|
||||
408,312,57,56,184,420,271,431,756,906,90,495,671,559,260,102,851,838,945,831
|
||||
492,801,412,819,269,228,263,352,632,137,60,143,569,675,356,557,144,491,794,581
|
||||
861,93,411,892,445,287,358,572,411,505,85,604,677,602,208,453,583,572,618,486
|
||||
672,696,708,894,947,944,472,747,365,204,483,745,851,435,680,193,521,583,132,137
|
||||
291,430,487,746,447,305,576,678,430,586,615,628,57,201,739,835,70,596,195,512
|
||||
709,601,690,201,204,735,55,620,95,892,515,340,313,752,400,766,550,93,448,794
|
||||
184,948,901,580,886,859,943,566,281,765,182,726,88,89,568,469,578,193,724,552
|
||||
607,350,308,949,934,106,513,203,736,264,564,518,212,834,760,525,667,913,858,321
|
||||
444,410,941,688,210,399,140,679,857,162,716,801,484,617,675,293,349,551,95,682
|
||||
849,192,488,552,946,191,400,190,51,770,266,523,438,423,917,678,947,631,290,412
|
||||
858,462,212,889,612,389,671,177,291,183,907,669,292,65,768,669,138,205,549,356
|
||||
373,696,894,834,452,564,101,838,721,354,711,475,234,890,287,456,444,525,938,838
|
||||
513,148,851,484,683,418,462,197,206,712,343,271,602,684,355,234,897,942,232,503
|
||||
276,941,459,694,584,598,716,709,617,710,682,900,201,756,915,798,69,55,233,445
|
||||
792,583,393,580,232,454,596,685,595,672,599,87,713,918,582,88,69,794,348,60
|
||||
133,57,800,526,263,420,392,801,628,747,898,102,460,95,756,147,489,568,103,330
|
||||
920,562,936,486,675,441,994,188,903,560,69,66,344,945,594,520,288,726,861,564
|
||||
521,525,337,712,342,423,684,450,55,97,354,903,802,460,101,221,902,58,57,733
|
||||
287,220,596,502,275,260,97,559,735,497,220,146,345,557,939,801,416,511,687,996
|
||||
397,734,626,527,528,271,744,846,885,672,619,195,627,189,720,201,754,802,308,485
|
||||
261,502,96,687,689,202,733,947,331,287,560,785,682,54,589,466,508,628,397,702
|
||||
274,417,532,104,598,524,859,757,689,174,522,907,219,791,989,741,936,268,197,858
|
||||
133,519,856,672,437,357,753,531,551,407,268,324,188,341,609,806,457,371,896,279
|
||||
425,896,509,752,801,897,502,579,530,308,566,308,918,230,741,918,797,395,292,540
|
||||
352,370,794,338,835,486,182,610,524,573,211,735,262,623,601,727,269,614,507,580
|
||||
519,629,753,613,978,310,353,407,458,857,419,726,88,568,744,907,750,393,741,433
|
||||
464,464,135,102,172,64,292,94,912,328,183,105,260,732,713,508,437,442,423,578
|
||||
575,427,861,498,558,796,526,703,265,630,450,104,355,186,387,603,486,748,185,932
|
||||
635,853,410,188,688,189,438,740,705,411,945,491,145,195,438,699,743,733,626,721
|
||||
671,752,200,294,909,427,573,344,753,756,290,712,697,523,903,560,214,176,141,702
|
||||
619,530,134,760,344,223,706,626,98,198,756,425,686,797,453,522,453,932,406,489
|
||||
489,589,312,628,497,328,736,903,717,518,176,907,412,702,598,261,260,837,90,577
|
||||
806,512,471,447,624,683,513,727,595,307,615,350,897,577,465,161,192,144,578,531
|
||||
800,728,920,55,754,684,54,202,51,761,612,436,999,935,626,919,100,405,51,173
|
||||
854,235,229,692,497,90,453,342,895,449,442,345,198,681,611,51,670,839,802,1
|
||||
267,584,550,217,572,403,602,694,467,234,523,857,211,992,593,191,503,467,711,949
|
||||
374,354,177,341,704,683,508,342,522,394,559,458,221,463,679,444,903,934,579,490
|
||||
515,456,787,893,704,427,986,314,741,894,507,50,761,532,569,409,343,462,723,726
|
||||
61,449,524,491,621,212,428,422,511,670,103,732,397,199,619,473,150,809,426,690
|
||||
626,510,492,623,235,405,190,188,899,449,389,570,802,621,683,451,790,748,685,918
|
||||
619,789,502,491,604,770,905,719,182,633,600,105,754,13,508,594,941,100,892,355
|
||||
96,140,133,482,765,647,687,405,188,708,859,185,410,454,355,742,431,97,916,88
|
||||
572,497,178,802,685,64,359,889,919,596,529,601,630,141,65,621,892,354,52,806
|
||||
672,583,264,214,508,787,423,457,610,904,88,898,20,700,147,513,597,619,934,678
|
||||
855,293,805,228,93,570,440,341,912,226,524,739,529,220,569,71,718,712,728,324
|
||||
688,679,724,885,591,496,692,268,885,22,670,101,356,406,195,451,368,483,677,690
|
||||
890,359,408,307,63,212,104,453,232,945,357,838,205,144,522,94,746,407,411,701
|
||||
791,178,718,793,260,909,761,403,855,520,17,682,606,405,59,100,857,755,604,623
|
||||
104,406,758,185,502,293,587,489,100,291,769,226,351,792,208,52,742,529,674,799
|
||||
260,617,343,621,178,268,568,368,203,915,361,600,292,852,194,286,466,210,704,597
|
||||
398,336,771,232,723,667,571,62,197,851,549,684,195,261,408,707,188,90,192,351
|
||||
913,913,621,313,932,358,572,436,758,708,625,931,505,451,64,696,807,403,587,421
|
||||
605,699,573,563,271,272,436,466,915,530,67,262,319,758,373,948,584,750,431,674
|
||||
852,130,273,318,95,578,740,344,891,724,275,145,431,176,531,646,739,938,935,344
|
||||
360,397,310,373,576,260,178,407,937,214,286,393,274,180,671,584,146,173,518,529
|
||||
702,737,102,451,842,806,572,568,943,790,466,571,103,354,417,516,753,491,744,286
|
||||
710,314,750,379,560,193,185,399,515,750,490,682,90,853,561,628,745,368,582,766
|
||||
68,503,856,147,184,280,354,457,95,721,766,853,484,406,398,839,553,688,407,409
|
||||
768,565,808,671,414,61,320,512,214,472,371,795,407,677,647,744,919,715,809,629
|
||||
671,234,162,633,885,358,803,769,789,622,105,355,907,460,61,141,858,857,899,323
|
||||
912,852,324,432,943,130,803,686,230,525,905,589,370,100,623,606,687,199,461,931
|
||||
734,190,594,308,282,287,426,496,427,421,592,439,272,322,527,396,190,100,596,567
|
||||
411,59,765,590,175,358,792,612,761,886,409,795,789,564,140,482,70,527,525,936
|
||||
735,375,763,838,450,556,608,512,175,740,312,939,173,710,902,104,91,496,218,938
|
||||
678,550,578,888,144,568,589,52,137,759,463,235,293,890,145,50,288,287,165,392
|
||||
182,899,491,747,234,482,201,266,429,181,567,65,749,787,191,434,910,566,291,509
|
||||
607,494,273,549,674,88,63,234,493,507,127,438,669,370,67,326,852,762,210,463
|
||||
618,859,419,394,299,704,670,469,529,96,710,746,803,290,400,748,622,357,406,203
|
||||
595,66,95,720,190,66,599,463,684,105,106,295,790,455,447,524,274,322,734,562
|
||||
503,464,520,566,52,483,588,946,552,195,861,872,699,897,428,456,312,461,624,800
|
||||
346,193,507,441,608,309,356,184,98,177,64,505,722,938,371,175,212,551,280,407
|
||||
595,66,134,343,395,892,373,629,714,697,598,358,229,629,618,531,685,95,394,634
|
||||
733,393,692,414,94,748,423,52,710,307,421,731,229,891,852,618,723,344,374,771
|
||||
511,943,725,694,469,204,459,409,585,516,763,741,946,486,449,322,714,604,766,993
|
||||
770,500,91,561,717,272,770,600,403,302,700,174,411,66,188,514,407,234,755,942
|
||||
475,731,569,210,580,631,620,353,762,392,495,64,725,732,323,456,503,672,597,514
|
||||
765,692,945,280,217,214,92,325,672,684,890,95,674,788,711,837,767,677,523,739
|
||||
797,458,65,734,399,719,786,288,416,316,753,503,442,609,528,145,735,403,566,751
|
||||
698,748,687,574,861,803,727,372,469,576,811,205,919,416,895,235,231,418,947,202
|
||||
437,456,612,630,549,670,806,806,222,705,516,404,470,607,440,748,54,747,602,885
|
||||
502,815,723,198,447,768,396,395,463,509,521,57,407,670,895,853,889,733,629,613
|
||||
616,619,54,442,949,591,800,804,133,630,271,271,724,513,1,570,633,750,598,104
|
||||
60,531,942,53,679,578,448,642,750,711,344,762,90,175,98,437,678,688,509,895
|
||||
793,736,721,178,90,451,102,502,444,728,934,393,744,981,732,322,144,59,584,558
|
||||
706,460,498,752,313,672,179,604,609,274,685,532,197,5,105,272,450,805,941,308
|
||||
447,525,53,203,571,436,505,519,315,594,466,228,506,787,358,711,801,418,88,914
|
||||
196,809,174,498,674,64,291,852,803,550,202,630,63,499,460,938,767,133,13,101
|
||||
896,791,715,95,512,199,854,490,672,50,990,943,556,630,261,57,520,890,266,187
|
278
days/day16.go
Normal file
278
days/day16.go
Normal file
@ -0,0 +1,278 @@
|
||||
package days
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const ()
|
||||
|
||||
var (
|
||||
rules = make(map[string][]int)
|
||||
myTicket = make([]int, 0)
|
||||
otherTickets = make([][]int, 0)
|
||||
ruleRegex = regexp.MustCompile(`(.+): (\d+)-(\d+) or (\d+)-(\d+)`)
|
||||
)
|
||||
|
||||
func atoi(val string) int {
|
||||
iVal, err := strconv.Atoi(val)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return iVal
|
||||
}
|
||||
|
||||
func atol(val string) int64 {
|
||||
iVal, err := strconv.ParseInt(val, 10, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return iVal
|
||||
}
|
||||
|
||||
func msDuration(startTime time.Time) float64 {
|
||||
return float64(time.Since(startTime)) / 1000000
|
||||
}
|
||||
|
||||
// Day16 runs day 16
|
||||
func Day16() {
|
||||
start := time.Now()
|
||||
makeList()
|
||||
log.Printf("Q16MakeList took %fms\n", msDuration(start))
|
||||
start = time.Now()
|
||||
part1()
|
||||
log.Printf("Q16Part1 took %fms\n", msDuration(start))
|
||||
start = time.Now()
|
||||
part2()
|
||||
log.Printf("Q16Part2 took %fms\n", msDuration(start))
|
||||
}
|
||||
|
||||
func makeList() {
|
||||
bytes, err := ioutil.ReadFile("16input.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fileStr := string(bytes)
|
||||
mode := 0
|
||||
for _, line := range strings.Split(fileStr, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
if len(line) == 0 {
|
||||
mode++
|
||||
continue
|
||||
}
|
||||
|
||||
switch mode {
|
||||
case 0:
|
||||
matches := ruleRegex.FindStringSubmatch(line)
|
||||
if matches == nil {
|
||||
panic("no regex match")
|
||||
}
|
||||
|
||||
rules[matches[1]] = []int{
|
||||
atoi(matches[2]),
|
||||
atoi(matches[3]),
|
||||
atoi(matches[4]),
|
||||
atoi(matches[5]),
|
||||
}
|
||||
break
|
||||
|
||||
case 1:
|
||||
if line == "your ticket:" {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, val := range strings.Split(line, ",") {
|
||||
myTicket = append(myTicket, atoi(val))
|
||||
}
|
||||
break
|
||||
|
||||
case 2:
|
||||
if line == "nearby tickets:" {
|
||||
continue
|
||||
}
|
||||
|
||||
otherTicket := make([]int, 0)
|
||||
for _, val := range strings.Split(line, ",") {
|
||||
otherTicket = append(otherTicket, atoi(val))
|
||||
}
|
||||
|
||||
otherTickets = append(otherTickets, otherTicket)
|
||||
break
|
||||
|
||||
case 3:
|
||||
panic("unexpected")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isValidForAnyRule(val int) bool {
|
||||
for rule := range rules {
|
||||
if isValidForRule(val, rule) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func isValidForRule(val int, rule string) bool {
|
||||
if (val >= rules[rule][0] && val <= rules[rule][1]) || (val >= rules[rule][2] && val <= rules[rule][3]) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func isValidTicket(ticket []int) bool {
|
||||
for _, val := range ticket {
|
||||
if !isValidForAnyRule(val) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func part1() {
|
||||
invalidValues := make([]int, 0)
|
||||
for _, ticket := range otherTickets {
|
||||
for _, val := range ticket {
|
||||
if !isValidForAnyRule(val) {
|
||||
invalidValues = append(invalidValues, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result := 0
|
||||
for _, val := range invalidValues {
|
||||
result += val
|
||||
}
|
||||
|
||||
log.Printf("Q16part1: invalid sum=%d\n", result)
|
||||
}
|
||||
|
||||
func part2() {
|
||||
validTickets := make([][]int, 0)
|
||||
for _, ticket := range otherTickets {
|
||||
if isValidTicket(ticket) {
|
||||
validTickets = append(validTickets, ticket)
|
||||
}
|
||||
}
|
||||
|
||||
ruleMatches := make(map[string][]int)
|
||||
|
||||
for ruleName := range rules {
|
||||
numCols := len(validTickets[0])
|
||||
for checkCol := 0; checkCol < numCols; checkCol++ {
|
||||
ruleValid := true
|
||||
for _, ticket := range validTickets {
|
||||
if !isValidForRule(ticket[checkCol], ruleName) {
|
||||
ruleValid = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ruleValid {
|
||||
ruleMatches[ruleName] = append(ruleMatches[ruleName], checkCol)
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := ruleMatches[ruleName]; !ok {
|
||||
panic("didn't map column to rule")
|
||||
}
|
||||
}
|
||||
|
||||
finalMap := make(map[string]int)
|
||||
ruleMatched := func(test string) bool {
|
||||
for name := range finalMap {
|
||||
if name == test {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
valMatched := func(test int) bool {
|
||||
for _, val := range finalMap {
|
||||
if val == test {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
for len(finalMap) < len(ruleMatches) {
|
||||
for ruleName, ruleVals := range ruleMatches {
|
||||
if ruleMatched(ruleName) {
|
||||
continue
|
||||
}
|
||||
|
||||
unmatchedVals := 0
|
||||
unmatchedValIdx := 0
|
||||
for idx, val := range ruleVals {
|
||||
if !valMatched(val) {
|
||||
unmatchedVals++
|
||||
unmatchedValIdx = idx
|
||||
}
|
||||
}
|
||||
if unmatchedVals == 1 {
|
||||
finalMap[ruleName] = ruleVals[unmatchedValIdx]
|
||||
continue
|
||||
}
|
||||
|
||||
for _, val := range ruleVals {
|
||||
if valMatched(val) {
|
||||
continue
|
||||
}
|
||||
|
||||
numMatches := 0
|
||||
for checkRule, checkVals := range ruleMatches {
|
||||
if ruleMatched(checkRule) {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, checkVal := range checkVals {
|
||||
if checkVal == val {
|
||||
numMatches++
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if numMatches == 1 {
|
||||
finalMap[ruleName] = val
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ruleForColumn := func(col int) string {
|
||||
for name, checkVal := range finalMap {
|
||||
if col == checkVal {
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("no rule found for column %d", col))
|
||||
}
|
||||
|
||||
finalVal := 1
|
||||
for idx, val := range myTicket {
|
||||
rule := ruleForColumn(idx)
|
||||
if strings.HasPrefix(rule, "departure ") {
|
||||
finalVal *= val
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Q16part2: departures multiplied=%d\n", finalVal)
|
||||
}
|
Reference in New Issue
Block a user