.
authorMart Lubbers <mart@martlubbers.net>
Thu, 17 Dec 2020 12:58:39 +0000 (13:58 +0100)
committerMart Lubbers <mart@martlubbers.net>
Thu, 17 Dec 2020 12:58:39 +0000 (13:58 +0100)
16/input [new file with mode: 0644]
16/input2 [new file with mode: 0644]
16/one.icl [new file with mode: 0644]

diff --git a/16/input b/16/input
new file mode 100644 (file)
index 0000000..fb2e40b
--- /dev/null
+++ b/16/input
@@ -0,0 +1,263 @@
+departure location: 27-180 or 187-953
+departure station: 47-527 or 545-958
+departure platform: 36-566 or 572-973
+departure track: 37-497 or 505-971
+departure date: 47-707 or 719-969
+departure time: 36-275 or 290-949
+arrival location: 31-855 or 864-955
+arrival station: 50-148 or 158-949
+arrival platform: 50-441 or 467-965
+arrival track: 30-648 or 659-962
+class: 26-470 or 481-966
+duration: 27-808 or 818-958
+price: 49-769 or 784-970
+route: 49-796 or 809-964
+row: 42-362 or 383-971
+seat: 34-877 or 887-952
+train: 31-354 or 363-950
+type: 39-208 or 231-953
+wagon: 47-736 or 746-968
+zone: 44-290 or 310-974
+
+your ticket:
+97,61,53,101,131,163,79,103,67,127,71,109,89,107,83,73,113,59,137,139
+
+nearby tickets:
+93,566,873,796,908,899,408,393,621,571,546,549,494,631,940,491,561,108,395,258
+609,949,551,408,648,723,627,428,905,665,248,557,630,169,494,583,680,658,677,385
+52,162,200,939,70,636,569,940,187,50,683,612,610,317,918,550,271,917,434,525
+869,266,108,172,338,615,791,824,117,191,623,838,108,174,169,164,207,238,867,569
+495,939,525,545,420,945,657,66,142,147,245,98,262,314,428,524,523,385,610,124
+648,512,273,820,514,83,146,670,911,855,331,637,729,409,240,344,316,201,498,63
+480,854,320,389,509,660,312,678,117,411,99,134,491,854,854,688,336,670,141,334
+925,405,791,599,831,853,208,587,584,271,563,754,822,66,910,186,701,623,633,483
+942,873,424,675,414,667,163,172,413,85,518,830,598,680,371,694,235,238,948,576
+398,627,429,899,942,92,82,172,805,389,523,408,849,335,199,119,581,789,195,520
+749,729,640,134,644,720,75,946,728,91,786,333,267,596,898,379,188,667,623,273
+117,235,948,240,412,178,552,60,289,790,564,240,684,684,505,829,319,793,662,587
+191,680,135,415,661,757,590,829,650,643,634,314,115,167,546,904,666,939,233,522
+576,722,272,492,481,79,864,343,749,244,131,398,382,677,481,407,160,199,424,491
+340,616,602,847,431,607,704,560,678,914,667,748,754,651,627,785,338,316,60,888
+163,62,726,431,902,588,240,678,161,708,71,160,935,432,159,338,122,312,633,418
+892,825,112,144,326,99,257,877,495,54,868,684,342,316,883,672,841,631,790,256
+867,254,169,514,421,184,53,468,932,169,496,526,113,627,441,239,623,60,672,386
+495,471,831,557,846,251,491,921,915,395,438,595,681,76,597,845,103,573,638,108
+634,876,705,69,670,484,608,203,896,753,196,252,304,913,769,613,238,147,118,419
+168,345,410,401,491,95,588,160,898,51,352,640,328,325,56,519,628,168,568,827
+870,894,707,98,57,701,329,692,594,140,948,927,902,682,489,707,616,355,912,90
+469,202,470,147,787,91,406,69,52,750,419,548,137,315,660,249,929,509,9,892
+441,63,550,88,433,893,619,891,659,690,261,699,786,546,358,174,346,820,259,395
+348,672,467,641,687,254,433,343,644,132,158,332,422,313,131,925,644,13,892,240
+905,547,697,431,384,757,906,491,180,575,761,317,287,176,342,707,385,441,556,609
+683,235,703,899,607,577,7,483,640,341,235,61,551,312,351,420,613,348,760,766
+726,934,247,723,656,51,897,612,337,892,244,423,166,560,661,248,106,267,593,274
+423,838,671,192,637,470,490,261,627,333,590,83,183,95,843,249,870,518,384,525
+75,893,681,527,638,319,321,949,258,925,853,259,508,416,432,311,613,978,393,661
+400,818,549,611,116,390,660,702,241,776,606,69,487,342,435,663,590,57,434,671
+249,941,730,547,604,315,136,202,933,503,758,105,566,267,164,208,704,936,510,618
+435,831,581,162,138,827,564,336,846,563,243,597,698,352,399,662,699,555,717,263
+438,85,833,764,926,866,188,839,191,259,875,110,220,334,667,254,908,263,594,852
+319,61,527,343,143,684,232,672,146,140,338,61,205,991,271,832,137,394,129,252
+698,487,489,118,902,701,700,347,630,264,56,405,238,696,607,857,919,638,554,177
+565,933,763,206,201,525,561,925,57,854,519,639,195,606,55,235,415,469,782,764
+139,614,244,164,648,200,722,429,113,75,842,892,384,837,718,840,343,399,315,795
+393,54,63,410,101,244,697,875,580,439,354,764,390,931,171,901,423,22,627,165
+700,595,126,101,497,250,732,241,602,919,243,592,55,4,133,922,552,937,917,487
+728,144,338,179,341,630,606,59,826,897,553,597,245,314,926,215,235,352,751,490
+387,854,190,172,206,824,513,429,904,768,413,470,704,106,348,244,790,124,356,598
+315,639,676,116,682,552,98,127,72,250,998,903,97,341,927,129,595,423,511,894
+438,919,824,580,178,507,671,627,762,927,828,572,139,192,550,493,597,178,279,820
+589,400,349,178,613,605,239,265,96,676,561,202,358,394,610,334,79,99,494,191
+165,791,416,135,920,830,736,93,55,426,626,791,330,764,117,108,396,999,82,685
+360,903,854,159,627,394,580,628,404,916,661,69,908,518,675,693,836,64,696,646
+198,509,114,525,607,387,405,145,66,208,122,626,88,95,937,501,586,912,241,785
+290,348,643,203,317,552,397,594,82,555,66,516,500,591,522,948,594,921,509,579
+553,254,137,433,427,516,95,173,411,206,243,829,166,934,683,275,919,571,347,549
+667,87,385,193,672,315,692,599,513,191,525,319,571,75,619,434,122,110,598,733
+68,392,731,823,833,874,8,432,693,415,927,344,693,593,167,439,686,163,249,947
+934,67,240,895,401,670,327,327,482,901,348,199,324,919,133,781,55,854,682,52
+412,496,832,914,102,896,191,167,481,319,867,665,978,747,553,143,790,719,582,790
+788,876,844,574,988,419,699,137,835,331,680,385,139,490,248,488,321,689,233,554
+517,534,179,490,415,750,595,614,194,352,598,666,873,635,749,491,62,630,135,623
+842,241,10,583,617,624,903,516,419,624,178,608,929,818,690,411,579,786,496,726
+77,432,401,125,147,730,842,441,502,249,431,146,68,106,626,103,869,346,258,99
+106,148,820,842,904,357,330,113,160,707,399,339,487,632,925,249,562,272,667,311
+415,820,75,68,415,834,202,933,521,578,416,73,894,108,401,357,794,318,167,341
+492,923,605,792,248,641,497,913,631,694,722,598,103,795,392,579,191,98,472,73
+936,260,206,167,110,895,395,484,930,491,50,751,802,526,665,721,677,508,662,489
+911,911,676,52,521,430,358,512,251,75,90,663,732,160,435,876,548,113,675,347
+193,687,353,941,893,189,73,118,439,507,429,184,328,764,761,507,751,696,845,724
+787,760,752,66,517,265,662,346,644,56,562,110,638,480,421,207,258,318,64,399
+626,639,705,978,525,84,265,889,516,905,587,525,762,586,338,167,694,108,262,764
+727,699,126,731,161,613,678,316,68,595,425,658,94,850,77,525,636,258,789,648
+840,338,631,144,142,759,63,107,766,681,909,389,703,470,858,948,249,618,722,165
+68,329,735,175,414,81,932,251,331,238,192,474,233,431,515,945,513,558,747,639
+191,158,314,840,705,793,895,119,570,102,246,520,831,870,85,577,843,158,488,676
+721,764,995,135,607,753,413,107,766,136,751,823,124,487,190,943,231,575,142,341
+419,354,315,852,84,363,350,146,832,387,328,866,825,314,126,412,575,313,686,702
+430,526,511,846,593,431,681,512,727,949,550,407,481,325,583,310,911,737,640,510
+630,495,933,997,620,111,628,122,700,272,572,628,392,174,137,909,122,692,207,766
+84,97,758,334,648,672,722,516,912,846,849,77,709,908,929,937,747,114,753,404
+636,383,252,723,786,687,786,685,690,916,917,250,827,643,800,648,195,232,623,198
+74,92,658,938,496,265,907,193,635,492,636,833,925,483,423,240,821,313,178,942
+768,344,557,64,22,849,386,554,637,313,88,723,350,176,233,597,618,76,849,79
+413,345,226,248,637,490,579,194,315,944,899,939,763,637,614,701,432,505,602,260
+585,648,248,663,389,394,870,692,332,88,89,704,88,197,15,260,597,395,922,933
+74,76,944,516,789,440,601,315,686,208,727,283,197,647,140,600,902,847,481,795
+494,419,272,250,612,259,835,932,86,679,434,172,633,420,774,705,82,597,917,126
+556,184,116,411,900,845,247,107,854,109,392,76,706,921,115,619,397,234,900,866
+241,256,591,566,203,68,733,700,874,521,145,470,427,641,137,467,553,608,651,416
+826,785,527,638,767,691,419,11,604,926,129,96,899,191,187,137,252,832,176,822
+410,385,854,702,934,752,766,669,123,987,625,120,187,344,339,914,592,247,662,77
+77,396,751,621,599,521,227,912,682,728,269,619,338,758,905,96,433,605,918,589
+115,673,673,619,663,138,322,604,566,901,656,628,572,794,933,89,697,719,728,241
+5,198,735,344,316,138,747,867,58,195,388,159,487,430,235,908,343,762,175,593
+243,818,77,892,85,555,523,554,932,758,864,591,833,201,640,476,557,626,665,272
+735,870,316,163,921,755,406,317,356,916,269,488,685,85,598,938,195,258,702,324
+893,98,520,751,341,564,189,262,261,372,648,164,508,75,72,205,704,432,851,133
+85,651,747,719,86,384,440,524,236,71,848,403,231,845,60,340,551,687,180,827
+696,704,518,514,61,661,688,349,339,437,95,235,898,50,738,332,596,896,844,872
+15,388,555,118,747,521,126,585,668,695,190,927,757,61,56,837,935,895,467,260
+484,546,796,976,831,829,168,871,399,440,627,919,493,405,661,687,913,706,764,768
+325,686,164,470,146,139,140,896,852,326,910,246,929,891,248,796,746,385,696,361
+638,56,588,887,791,663,99,790,622,942,476,746,747,625,60,398,927,721,496,275
+86,742,705,640,659,128,172,176,874,310,548,67,606,106,169,134,546,823,267,825
+613,933,872,756,334,518,507,630,338,736,468,633,726,78,72,202,412,224,701,696
+683,132,689,874,916,245,146,431,246,606,414,735,986,761,934,640,941,439,250,165
+118,134,123,98,598,345,478,927,436,931,769,876,834,68,104,912,892,647,200,674
+399,417,836,729,87,581,773,852,98,928,906,352,88,927,346,429,106,736,753,913
+121,731,79,434,941,641,236,672,599,105,943,441,103,731,567,769,173,116,731,187
+526,636,244,511,92,558,510,612,897,644,730,745,100,823,580,52,854,141,384,122
+591,607,201,204,610,96,402,652,734,426,496,263,552,704,235,433,588,198,126,896
+59,854,902,175,165,111,428,869,587,92,932,129,884,636,204,349,694,525,90,547
+849,623,107,107,327,81,238,425,636,441,666,373,841,830,117,906,142,165,769,109
+314,507,81,106,749,733,144,208,84,93,140,405,623,751,341,913,918,371,180,907
+842,936,178,506,746,739,931,929,467,579,59,249,440,753,314,672,702,58,577,632
+391,161,421,796,946,640,752,930,409,266,67,528,795,941,586,906,208,556,905,506
+851,489,52,162,111,616,763,846,948,471,910,247,642,514,646,904,749,115,53,822
+488,623,558,898,110,599,401,904,512,333,492,431,668,389,174,658,161,837,792,842
+290,366,846,81,735,627,73,639,635,140,272,332,267,823,912,607,659,331,260,908
+560,242,626,758,179,70,57,831,143,61,143,103,96,849,314,173,274,597,5,945
+593,135,512,354,786,469,896,112,165,188,63,728,659,128,845,436,191,108,113,478
+252,441,506,412,53,251,69,731,324,832,576,777,638,648,588,513,416,58,820,676
+771,730,722,606,603,92,481,169,135,348,76,139,589,894,78,424,333,111,929,325
+428,619,67,603,725,605,67,593,412,112,661,198,148,579,211,407,332,505,666,114
+105,843,764,235,174,827,511,784,920,243,104,423,326,916,941,280,487,901,677,790
+424,392,414,674,929,489,836,423,907,408,121,607,113,163,934,535,177,253,485,407
+748,189,843,396,629,818,345,677,601,174,85,240,912,195,108,570,849,245,707,427
+604,559,638,424,514,255,720,668,341,469,548,418,791,754,60,879,922,706,628,432
+760,840,661,340,247,584,320,92,720,743,938,752,73,256,606,97,87,489,125,618
+100,140,679,273,92,676,99,641,259,945,785,848,472,946,332,912,268,706,676,126
+923,126,435,752,108,282,576,95,790,138,933,61,205,682,482,240,338,315,270,618
+920,917,177,120,201,534,107,828,766,796,179,275,61,118,506,628,470,735,669,725
+58,993,325,647,945,935,346,62,238,113,497,135,432,59,83,677,483,275,561,610
+609,416,496,492,52,401,428,621,565,390,999,234,572,907,344,131,78,618,135,333
+583,493,671,618,706,328,122,488,795,387,830,391,608,343,494,547,631,135,210,935
+158,343,507,254,629,251,719,255,923,546,671,557,928,842,448,106,139,765,546,90
+866,906,72,945,497,930,527,198,768,427,423,594,834,353,769,843,770,830,930,252
+525,262,927,664,255,568,825,606,620,678,616,481,850,91,852,930,645,875,203,726
+257,526,129,386,691,13,330,769,833,665,849,270,766,100,264,521,602,343,892,924
+403,176,794,687,903,431,511,506,588,486,256,139,605,666,502,467,161,61,920,706
+842,761,399,870,171,337,724,72,234,253,243,935,158,931,538,267,421,789,697,684
+744,643,754,413,850,486,587,346,160,487,425,437,576,606,310,894,117,434,870,751
+423,608,313,68,849,323,403,238,275,603,839,712,916,125,619,231,867,330,622,621
+368,251,828,79,843,913,406,664,391,324,415,51,830,148,253,77,176,131,333,506
+233,417,98,432,66,595,98,935,489,843,343,670,785,841,424,445,590,731,600,645
+938,436,329,918,944,646,660,607,130,598,253,82,406,395,488,814,322,833,872,572
+354,273,196,316,735,614,663,706,589,876,125,502,430,61,128,747,518,902,575,57
+824,788,167,433,579,423,314,788,229,518,125,102,945,78,594,170,172,663,527,493
+102,413,930,129,516,555,484,327,385,114,662,213,766,206,623,159,59,86,752,666
+173,648,520,321,328,582,524,938,413,332,925,74,330,514,722,715,919,759,511,907
+588,594,171,83,525,412,260,888,235,440,347,517,117,920,176,754,726,421,639,775
+827,722,509,422,54,455,932,761,64,757,315,562,86,836,846,565,430,785,545,434
+51,315,629,916,84,611,331,97,626,255,352,194,894,247,337,755,259,868,988,526
+127,146,330,733,168,128,926,165,924,889,390,914,929,820,824,60,784,781,870,397
+319,241,553,693,475,107,493,693,207,700,946,481,104,855,160,86,830,564,769,188
+671,196,926,169,338,690,761,125,75,767,729,521,405,919,472,141,918,580,424,558
+255,487,268,199,898,679,869,395,948,790,62,361,341,438,866,564,866,330,323,625
+832,97,190,207,603,825,434,484,347,765,776,749,788,313,792,236,402,600,429,870
+706,58,565,84,148,819,629,791,18,235,889,331,868,505,934,606,336,72,914,560
+399,610,722,837,401,915,767,727,441,983,898,622,785,494,896,690,678,645,244,83
+867,335,266,620,821,340,831,898,897,558,730,243,655,199,562,610,794,689,672,352
+550,586,21,949,86,484,624,168,426,764,139,315,595,274,930,203,833,319,205,613
+408,638,700,904,346,930,428,897,320,87,767,429,107,416,273,197,272,693,618,741
+839,88,552,582,686,124,894,236,612,54,737,134,945,660,853,431,659,911,140,496
+103,626,394,59,62,431,332,70,602,623,600,333,350,509,395,144,51,611,543,315
+354,196,578,698,564,934,317,561,853,262,919,594,943,101,278,874,318,324,732,706
+587,225,908,386,403,870,595,677,661,506,141,830,127,265,663,584,321,705,395,256
+248,909,923,389,274,563,51,165,142,229,732,201,412,584,704,864,584,414,485,328
+604,252,413,891,405,132,892,432,699,754,208,121,177,788,693,721,853,488,737,118
+242,659,789,877,662,240,501,237,482,193,761,314,393,834,785,903,432,786,246,66
+900,669,129,596,486,547,523,628,711,515,592,555,606,163,117,158,628,397,172,551
+849,280,412,693,640,582,581,928,62,849,582,689,68,241,114,931,496,56,334,189
+693,855,831,788,731,395,441,920,438,283,430,317,925,490,719,90,79,316,256,481
+939,734,523,62,887,595,273,124,582,927,127,395,591,409,727,292,755,836,747,134
+895,569,767,487,723,729,482,386,730,891,54,606,599,257,899,572,512,923,409,148
+749,502,551,824,666,339,769,663,233,602,343,682,316,327,824,387,252,512,247,64
+520,351,875,12,79,518,101,140,106,794,142,95,920,107,96,401,615,159,564,828
+645,352,391,54,251,95,208,686,439,651,236,118,384,271,832,588,753,254,682,762
+835,949,387,614,96,219,399,680,441,513,232,412,254,427,208,925,838,128,589,576
+129,319,615,601,928,94,819,919,729,759,164,625,791,683,877,481,215,425,333,189
+432,65,627,121,692,579,197,418,557,614,850,117,870,318,305,671,612,145,759,238
+789,355,126,511,158,923,264,853,765,557,275,141,195,237,109,272,914,422,242,180
+267,581,835,722,481,875,350,233,475,93,90,250,325,623,683,698,837,695,128,402
+920,130,664,268,606,16,313,261,269,545,435,685,102,828,618,140,829,492,231,403
+707,866,752,237,546,526,563,351,901,315,254,414,682,124,233,926,635,414,61,377
+551,310,733,891,785,343,207,202,241,468,846,616,533,527,791,328,839,851,207,387
+728,581,614,723,353,196,622,787,723,827,660,71,430,337,572,755,650,234,684,168
+652,788,929,72,193,203,423,751,140,324,893,903,935,519,164,556,896,855,907,257
+438,931,556,891,234,655,164,429,614,202,597,337,703,387,89,170,727,208,429,110
+575,70,469,54,127,430,583,111,877,167,916,705,794,168,519,737,648,493,662,746
+581,71,338,843,898,320,580,505,421,676,367,887,736,690,525,621,575,67,316,63
+418,761,668,343,831,522,602,847,163,402,828,239,167,86,527,523,235,697,3,517
+65,732,910,894,603,591,101,870,542,691,256,312,916,180,86,829,855,788,159,907
+692,202,942,581,561,524,410,876,776,70,825,118,833,82,611,345,389,838,203,829
+616,805,706,327,827,107,179,583,840,633,89,396,175,584,939,397,172,793,392,581
+90,244,275,793,926,163,790,865,147,758,421,640,611,71,512,81,576,84,324,502
+419,199,545,166,438,499,873,687,855,930,401,120,843,616,704,171,59,526,385,748
+690,146,482,143,82,204,627,313,904,720,73,1,551,496,590,339,395,686,663,429
+79,853,109,993,938,237,405,336,346,179,566,865,133,664,629,132,785,604,54,256
+896,196,779,646,260,485,624,562,415,89,75,131,848,900,928,326,468,914,200,789
+79,100,400,265,621,769,750,527,394,439,895,787,418,510,635,842,376,108,508,178
+484,178,411,128,931,720,749,66,416,359,584,614,844,684,746,722,126,594,696,333
+507,659,190,338,271,310,372,232,671,91,486,93,179,686,873,664,468,347,202,347
+676,411,894,897,747,431,874,927,455,846,874,521,133,599,721,148,522,940,142,97
+867,617,111,692,854,846,986,195,512,752,894,924,172,384,350,92,204,565,269,516
+823,412,126,387,696,493,140,720,201,734,665,874,179,3,887,601,132,248,662,392
+100,435,671,118,77,795,547,828,188,674,161,915,727,562,243,839,23,791,581,338
+187,269,874,694,582,71,330,198,936,176,936,611,133,80,946,134,5,697,756,486
+344,758,429,666,592,140,740,580,437,937,105,387,572,549,241,269,249,825,164,639
+413,429,142,353,163,519,762,611,435,619,87,930,249,641,514,421,125,478,835,668
+137,753,616,158,251,110,701,162,392,865,641,570,638,241,331,936,558,732,124,253
+125,403,593,928,665,521,599,829,874,679,83,388,188,949,758,806,730,574,180,103
+290,146,835,119,753,710,727,664,80,81,242,91,125,135,526,75,83,573,204,894
+223,86,69,71,644,561,90,719,525,208,77,194,896,733,522,581,195,558,267,180
+525,106,78,164,698,774,290,894,340,272,482,232,427,584,398,424,270,245,104,485
+92,242,324,468,232,477,686,839,101,616,557,202,406,491,922,103,930,706,419,193
+763,402,256,894,55,521,124,66,639,111,386,439,584,985,911,942,238,389,919,135
+929,935,791,681,686,996,317,417,636,874,635,573,331,74,388,899,831,648,581,619
+327,259,65,440,273,948,675,326,167,52,331,250,17,696,162,121,583,829,524,675
+705,783,423,481,919,483,257,735,102,86,333,197,417,736,486,840,641,326,424,733
+575,788,486,387,846,830,874,660,905,62,250,405,198,825,649,145,553,523,685,108
+509,688,506,107,762,800,247,688,900,388,256,688,159,431,121,942,758,100,324,573
+352,669,490,159,178,145,416,494,693,559,679,606,704,927,994,391,612,483,637,756
+606,723,398,894,497,301,253,127,429,123,493,140,81,424,349,114,677,620,519,948
+829,510,606,111,233,56,386,913,722,343,490,837,783,432,912,50,558,111,434,88
+924,520,750,515,556,323,161,786,182,623,189,841,924,603,349,347,69,707,833,98
+506,715,550,58,905,496,486,148,931,599,313,695,319,247,165,485,945,587,606,834
+70,496,174,392,948,833,935,942,146,144,165,554,466,891,117,488,74,102,467,582
+321,696,206,273,770,99,705,604,75,257,243,514,751,851,246,169,265,414,728,263
+322,123,827,203,386,176,121,82,406,584,247,766,679,311,184,916,824,83,618,484
+336,846,56,160,177,84,914,489,70,877,320,581,133,73,139,411,136,345,406,656
+270,160,50,135,918,354,107,338,368,146,752,723,115,728,518,89,695,576,833,925
+719,236,147,919,263,755,640,392,758,564,687,441,23,241,691,648,353,823,946,54
+689,103,320,481,248,915,695,405,738,550,943,335,406,719,561,424,317,269,92,926
+254,604,427,166,345,915,550,852,102,497,750,315,734,99,752,590,191,561,275,225
+490,666,672,925,170,986,52,71,158,342,167,633,141,290,313,419,731,665,949,784
+685,865,62,426,421,173,711,196,871,725,514,890,676,399,244,676,587,925,580,314
+845,115,327,340,236,103,130,749,580,337,209,867,81,74,427,914,426,591,312,137
+563,581,476,586,120,590,440,412,835,834,95,169,428,818,841,135,726,517,731,556
+848,2,267,96,81,354,121,667,417,758,128,613,193,388,140,926,614,82,266,238
+391,903,518,257,387,701,208,630,628,731,402,273,910,625,948,105,133,547,368,707
+432,517,64,394,67,429,899,888,677,603,114,691,919,61,329,663,476,645,677,387
+103,389,944,470,873,397,167,423,168,75,700,487,738,707,208,819,793,73,88,317
diff --git a/16/input2 b/16/input2
new file mode 100644 (file)
index 0000000..b48bf37
--- /dev/null
+++ b/16/input2
@@ -0,0 +1,11 @@
+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
diff --git a/16/one.icl b/16/one.icl
new file mode 100644 (file)
index 0000000..12cfe84
--- /dev/null
@@ -0,0 +1,76 @@
+module one
+
+import StdEnv
+import Data.Tuple
+import Data.Either
+import Data.Func
+import Data.List
+import Data.Functor
+import Control.Applicative
+import Control.Monad
+import Text.Parsers.Simple.ParserCombinators
+from Data.Set import :: Set
+import qualified Data.Set as DS
+
+read :: *File -> [Char]
+read f
+       # (ok, c, f) = freadc f
+       | not ok = []
+       = [c:read f]
+
+Start w
+       # (io, w) = stdio w
+       # (Right (fields, myticket, nearby)) = parse parseInput (read io)
+       # nearby = filter (not o isEmpty) nearby
+       = (one fields nearby, two fields myticket nearby)
+
+one fields = sum o flatten o map (filter \e->not $ isMember e $ flatten $ map snd fields)
+
+valid fields = isEmpty o filter \e->not $ isMember e $ flatten $ map snd fields
+
+foldr1 f [x:xs] = foldr f x xs
+foldr1 f [] = []
+
+intersect` [] xs = xs
+intersect` xs [] = xs
+intersect` ys xs = intersect ys xs
+
+// for every ticket, for every field, every option
+//two :: [([Char],[Int])] a [[Int]] -> [[[String]]]
+two fields myticket nearby = (\x->proc x x [] []) $ map (foldr1 intersect) $ transpose $ map (collectConstraints fields) $ filter (valid fields) nearby
+where
+       //Per field show all options for the field
+       collectConstraints :: [([Char], [Int])] [Int] -> [[String]]
+       collectConstraints fields fs = map collectConstraint fs
+       where
+               //For a field, return the possible fields
+               collectConstraint :: Int -> [String]
+               collectConstraint num = [toString f\\(f, rng)<-fields | isMember num rng]
+
+       proc :: [[String]] [[String]] [String] [[String]] -> [[String]]
+       proc orig [[x:xs]:xxs] acc accum = proc orig (map (filter ((<>)x)) xxs) [x:acc] $ proc orig [xs:xxs] acc accum
+       proc orig [[]:xxs] acc accum = proc orig xxs acc accum
+       proc orig [] acc accum = if (valid orig (reverse acc)) [acc:accum] accum
+       where
+               valid :: [[String]] [String] -> Bool
+               valid [x:xs] [y:ys]
+                       | isMember y x = valid xs ys
+               valid [] [] = True
+               valid _ _ = False
+
+parseInput :: Parser Char ([([Char], [Int])], [Int], [[Int]])
+parseInput = tuple3 <$> many pField
+       <* pStr ['\nyour ticket:\n'] <*> pSepBy pInt pComma <* pToken '\n'
+       <* pStr ['\nnearby tickets:\n'] <*> pSepBy (pSepBy pInt pComma) (pToken '\n')
+where
+       pField :: Parser Char ([Char], [Int])
+       pField = tuple <$> many (pSatisfy (\c->isAlpha c || c == ' ')) <* pStr [': '] <*> pRange <* pToken '\n'
+       where
+               pRange :: Parser Char [Int]
+               pRange = flatten <$> pSepBy ((\x y->[x..y]) <$> pInt <* pToken '-' <*> pInt) (pStr [' or '])
+
+       pInt :: Parser Char Int
+       pInt = toInt o toString <$> some pDigit
+
+       pStr :: ([Char] -> Parser Char [Char])
+       pStr = sequence o map pToken