diff options
-rw-r--r-- | 2020/fourteen.nim | 21 | ||||
-rw-r--r-- | 2020/input/fourteen.txt | 594 |
2 files changed, 615 insertions, 0 deletions
diff --git a/2020/fourteen.nim b/2020/fourteen.nim new file mode 100644 index 0000000..e333cf9 --- /dev/null +++ b/2020/fourteen.nim @@ -0,0 +1,21 @@ +# Day Fourteen: Docking Data +import os, strutils, sequtils + +let input: string = paramStr(1) +let program: seq[tuple[address, value: string]] = map(split(strip(readFile(input)), '\n'), + func (param: string): (string, string) = + (split(param, " = ")[0], split(param, " = ")[1])) + +var mask: string = repeat('X', 36) +var memory: seq[int] = newSeq[int](99999) +for line in program: + if line.address == "mask": + mask = line.value + elif line.address[0..2] == "mem": + var value: string = toBin(parseInt(line.value), 36) + for i, bit in mask: + if bit != 'X': + value[i] = bit + memory[parseInt(line.address[4..^2])] = fromBin[int](value) + +echo foldl(memory, a + b) diff --git a/2020/input/fourteen.txt b/2020/input/fourteen.txt new file mode 100644 index 0000000..ceb1f49 --- /dev/null +++ b/2020/input/fourteen.txt @@ -0,0 +1,594 @@ +mask = 0010X01001X010000110100000X000010X11 +mem[41717] = 288 +mem[54146] = 1656 +mem[30135] = 4799584 +mask = 01X10101X11X01XX01X000011X1000110110 +mem[29142] = 13227025 +mem[32455] = 1814 +mem[42522] = 385316684 +mem[29904] = 5334 +mem[51087] = 1492 +mask = 01110X1X1XX0100011X0111X11001X1X1001 +mem[16001] = 2818333 +mem[896] = 152318161 +mem[7380] = 1741200 +mem[36363] = 3994854 +mem[51852] = 5003 +mem[31197] = 8946048 +mem[38377] = 699057 +mask = 00XX0X11111001001XX100X1010X00X10X01 +mem[41981] = 8217309 +mem[929] = 5355 +mem[21551] = 1130885 +mask = 111X01X111001X0XX11X110100X1101100XX +mem[38540] = 877233 +mem[4594] = 156077284 +mem[17004] = 12673792 +mem[11717] = 12697488 +mem[58553] = 890949 +mask = 001101X101X1100001X0000X0X100001110X +mem[49613] = 14831731 +mem[18410] = 386265 +mem[11204] = 66992 +mem[7462] = 330749684 +mem[48489] = 186227974 +mem[49880] = 13957 +mem[37574] = 101061 +mask = 0X11010101111000011XX00001X0101111X0 +mem[43270] = 63321063 +mem[8868] = 8357760 +mem[51871] = 7561 +mem[59958] = 76822813 +mem[13346] = 298124646 +mem[28205] = 1479 +mem[20102] = 898175404 +mask = 00X00X11111001001X1X0000011010000101 +mem[39594] = 471 +mem[23863] = 472 +mem[45424] = 881 +mem[5520] = 68851082 +mask = 1111011X1XX01XX01110010X011010X01100 +mem[7932] = 7104 +mem[50570] = 521355116 +mem[33698] = 77366694 +mem[54041] = 1967898 +mem[1940] = 272765 +mem[42608] = 557758 +mem[48653] = 95074 +mask = 01110101011110001100100101X11000XX0X +mem[5032] = 324136 +mem[19968] = 25 +mem[37008] = 370 +mem[51927] = 7820968 +mem[3960] = 273343 +mem[26318] = 9940851 +mask = 11X1011X1X00111XX110X000011X10010001 +mem[49437] = 13322545 +mem[46843] = 690911 +mem[58945] = 13770143 +mem[4847] = 67337 +mem[6128] = 371 +mask = 1100X1X1X10011X01X100011110011110001 +mem[6466] = 926046 +mem[20503] = 8735222 +mem[29727] = 18641 +mem[20030] = 1090613 +mem[54347] = 33354545 +mask = 11XX01X111X011001110X0110101100XX011 +mem[59773] = 1775 +mem[31974] = 722 +mem[15867] = 46611 +mem[37151] = 3019104 +mem[21915] = 96864303 +mem[9222] = 10601111 +mem[20777] = 1235555 +mask = 0111010001111X00110X0X1011X0X1100000 +mem[46581] = 20573 +mem[32355] = 58869216 +mem[45378] = 13272459 +mem[22414] = 322109637 +mem[34083] = 20766732 +mem[63698] = 3924531 +mask = 010101011X100X01011001X10X101X11011X +mem[57710] = 113212 +mem[31202] = 231541678 +mem[51278] = 219614 +mem[63698] = 1042138 +mem[15026] = 7000054 +mem[51217] = 500505 +mask = 0X100001000X0100XX1XX1101101001X1000 +mem[7011] = 521173 +mem[13238] = 157620 +mem[30900] = 19373 +mem[27810] = 163020969 +mem[54982] = 96357825 +mem[22824] = 408599 +mem[12477] = 48103186 +mask = 00000010111XX00XX110X010000000010111 +mem[54146] = 17970 +mem[41376] = 1503 +mem[31900] = 438330985 +mem[13355] = 435056 +mem[64758] = 1052852148 +mem[59142] = 1950135 +mem[6781] = 13502 +mask = 01X10X0111110X00X0XX010100X10X1X0101 +mem[51107] = 13121312 +mem[20134] = 243 +mem[56802] = 24720 +mask = 1111010111101100XX101111000000010X1X +mem[56384] = 729 +mem[32508] = 258811315 +mem[39920] = 252650 +mem[54657] = 119337 +mem[43559] = 1614394 +mem[43973] = 36253 +mask = 00100XXXXX1X10000110110100010001XX01 +mem[33796] = 171340858 +mem[62392] = 2042140 +mem[21146] = 202316 +mem[50189] = 17797984 +mem[59958] = 3871673 +mem[46838] = 7418 +mask = X0100X0X111X11011110X0000001001X1111 +mem[35424] = 14950493 +mem[64240] = 40746 +mem[22319] = 149408 +mem[32929] = 57764 +mem[4571] = 138473 +mem[13202] = 6496022 +mem[59210] = 24648253 +mask = 00XX0001111011111110X1X0111010XX0X10 +mem[31028] = 3706 +mem[64362] = 57739 +mem[22920] = 491669 +mask = 011X0101X111XX000110XX01X110X001110X +mem[22272] = 22414 +mem[59958] = 10131 +mem[9299] = 59050364 +mem[54292] = 185609950 +mem[11363] = 679 +mem[55554] = 127124 +mask = 11110X0110X010101X10010X011010011011 +mem[13140] = 23895 +mem[54725] = 364383 +mem[12768] = 29526 +mem[21134] = 31494 +mem[32345] = 13843 +mem[38437] = 576352606 +mem[35535] = 1948 +mask = X111011111X100X001111111000X111000X0 +mem[34738] = 395933 +mem[33438] = 644 +mem[34480] = 56137 +mem[33415] = 71 +mem[55820] = 40580559 +mem[37978] = 104370 +mem[60594] = 47366315 +mask = 011X0X110110X000100X0X1110X00000XX00 +mem[2065] = 5611 +mem[42368] = 139274892 +mem[11145] = 48456 +mem[11668] = 5352867 +mem[40280] = 864639 +mask = 1XX1X00X11010X10011111XXX1101100111X +mem[39384] = 12733115 +mem[48860] = 24406 +mem[46230] = 13931503 +mask = 00X001100X11100001101100001X1XX10001 +mem[11204] = 11902 +mem[42496] = 95479 +mem[58594] = 120902 +mem[62260] = 43802019 +mem[41882] = 889 +mask = 00X000X011111X0001100000000000X00001 +mem[54549] = 73578351 +mem[15308] = 225676 +mask = 11110X011100100X11111111XX0101100111 +mem[62902] = 115296396 +mem[163] = 47992 +mem[27595] = 1080625 +mask = X01101X1111XX1X0111X0101000000111010 +mem[45311] = 950513 +mem[35853] = 3048594 +mem[25353] = 42914232 +mem[4595] = 165637540 +mem[5173] = 4666 +mem[27595] = 33115384 +mask = 11XX0101X10010000111X111001000X00111 +mem[5313] = 16770 +mem[21570] = 21589452 +mem[45537] = 25984 +mem[7425] = 1016 +mem[57579] = 4400441 +mem[16371] = 27936 +mem[29544] = 699 +mask = 0011010X1X1010X111X10X0001010XX01001 +mem[12546] = 66366447 +mem[4594] = 660822686 +mem[61425] = 3035 +mem[16121] = 27102624 +mem[1316] = 1781 +mem[23623] = 572865256 +mask = 0111X1011XX01X0101100100X110000X001X +mem[23341] = 6402065 +mem[52500] = 1977612 +mask = 00X0001011X1100001101100X01100X00111 +mem[64017] = 31705 +mem[35512] = 1445 +mem[35781] = 5233653 +mem[44050] = 40 +mask = 01110100X11110X0X1000X11111X0X1X000X +mem[12867] = 190010 +mem[36252] = 747672 +mem[23167] = 204357 +mem[27385] = 12016 +mem[47464] = 784707845 +mem[48043] = 627253 +mask = 0111X0X0X100100X1110011X11000X000100 +mem[37676] = 36371 +mem[59916] = 3315 +mem[29136] = 15854324 +mem[37249] = 132828 +mem[53802] = 79432 +mask = X11X1101101X110X0X10X1000011000XXX00 +mem[17461] = 8158 +mem[33712] = 1029431 +mem[1042] = 837675 +mask = 00110X011010100X1101010100010XX11011 +mem[16121] = 853733 +mem[18346] = 5303 +mem[60174] = 506801115 +mem[1817] = 1868 +mem[46166] = 168 +mem[14602] = 1968 +mem[5368] = 109371 +mask = X1110XX111X100X0011X101111001101XX10 +mem[21630] = 8667 +mem[55820] = 200651 +mem[11204] = 34034 +mask = 1111011X10101X001110001X01XX00010101 +mem[62846] = 105848 +mem[43437] = 28568 +mem[16213] = 724626106 +mem[32677] = 149932 +mem[23580] = 573 +mem[22272] = 3393406 +mem[64633] = 4838 +mask = 011001010XX1X10001100X00X0010001X0X0 +mem[23580] = 992 +mem[7692] = 1236 +mem[33389] = 560975 +mem[7177] = 5868 +mask = X1X10101X0101X0011101100111110100101 +mem[99] = 6843772 +mem[30553] = 554826032 +mem[61798] = 5939100 +mem[48169] = 2030 +mask = 00XX000100000X0001110010X11001000101 +mem[25353] = 78809 +mem[10239] = 276125 +mem[11223] = 13545 +mem[57147] = 1433 +mask = 001X010010011010X110101X11011X001010 +mem[49575] = 152755 +mem[26848] = 63016 +mem[30880] = 1725364 +mask = 011101X10XX01X0010X0XX01110000X11100 +mem[41287] = 414662075 +mem[28188] = 3477472 +mem[36592] = 7996235 +mem[49314] = 9140605 +mem[47488] = 7769 +mask = 01110X01X111010001X100101X0X10011100 +mem[52240] = 192560204 +mem[65031] = 701796 +mem[14783] = 8161 +mask = 0111010X011X1X001XX01001X1X00X0100X0 +mem[49691] = 10412561 +mem[915] = 134624030 +mem[8606] = 736 +mem[58998] = 1516 +mem[61106] = 641573 +mask = 01X1X1X111101011011X10100010000X01X1 +mem[21630] = 19000288 +mem[60944] = 213511689 +mem[46464] = 59732 +mem[32695] = 533 +mem[27385] = 25467104 +mem[62812] = 304550708 +mask = 00110X010X1110X0X1111X00111X0001X100 +mem[57194] = 24040 +mem[20550] = 46674 +mem[52168] = 23339025 +mem[35512] = 68290970 +mask = X111011X1010101011101X10000111000X11 +mem[12546] = 102729072 +mem[7304] = 110383 +mem[59523] = 888 +mem[21630] = 71914682 +mem[19910] = 5863216 +mask = 11X0010X1X101110111X01X0000111111001 +mem[4963] = 173772407 +mem[33919] = 81154860 +mem[7928] = 4393 +mem[59961] = 4977369 +mem[22493] = 377398427 +mask = 00X0010X10011X10X1X00001X10001101010 +mem[17461] = 120207 +mem[7618] = 54871412 +mem[3960] = 25088 +mem[4185] = 15852 +mask = X0X00X00011010000100001X001110010101 +mem[17246] = 10825 +mem[61485] = 1220754 +mem[37937] = 63325 +mem[13776] = 44579590 +mem[26933] = 467904 +mask = 01X10X011XX101001001X101X11110100111 +mem[51192] = 227116205 +mem[8996] = 589323 +mem[40539] = 2892 +mem[18976] = 329283 +mem[2942] = 13450 +mem[59167] = 436935 +mask = 0X11010101111000X11010XX011X1X010001 +mem[31621] = 4166 +mem[38132] = 66956 +mem[4178] = 32378 +mem[59276] = 448 +mem[57505] = 202001993 +mem[8239] = 69424389 +mask = 0010X10001101000X1X00000001000001X00 +mem[32804] = 120932430 +mem[60447] = 305 +mem[62385] = 5277 +mem[54940] = 11685990 +mem[48466] = 1956474 +mem[38326] = 14070 +mask = 1111010111X0101X11101000X0011X0000X0 +mem[9957] = 794590 +mem[43663] = 63819868 +mem[59142] = 8388971 +mem[41877] = 413661620 +mask = X011X10X111XXX001111010101XXX0011001 +mem[47] = 18787684 +mem[17443] = 648 +mem[4356] = 656 +mem[65126] = 3205798 +mem[38437] = 1762627 +mem[43834] = 581 +mask = 01110110X10010001100X01010101X0X1001 +mem[38345] = 934 +mem[58528] = 6065840 +mem[33800] = 20485490 +mem[48232] = 16644491 +mask = 001X000X00X001000X11XX10101010X111X0 +mem[22284] = 259142 +mem[28461] = 974 +mem[62938] = 449 +mem[40024] = 598 +mem[22913] = 650 +mem[19996] = 5093 +mask = 0X100X01X1X010XX01X00000010000100001 +mem[29565] = 3981254 +mem[55283] = 82851782 +mem[36252] = 55697822 +mask = 111101X11X101XX01110XX1010X101XX0101 +mem[56566] = 29617152 +mem[10468] = 2660883 +mem[28055] = 1499 +mem[35218] = 185790979 +mem[22128] = 846102 +mem[30117] = 560842 +mem[58299] = 1012387364 +mask = 111X010110X0X010111001X0X00X11011111 +mem[48718] = 3937 +mem[26689] = 501780 +mem[30553] = 657149 +mask = 001001XXX0X110X001100001X1X1111X0010 +mem[1480] = 42916 +mem[27601] = 42064531 +mem[35919] = 6321 +mem[57905] = 2686675 +mask = X1110X1X110010X01X101111010110X0X101 +mem[40159] = 28365 +mem[50570] = 95027 +mem[65427] = 4531 +mem[7468] = 41 +mem[49166] = 3783 +mem[59623] = 258901051 +mask = 1111011X1100100X111X0X0X11011X1001X0 +mem[58839] = 103790 +mem[44410] = 660 +mask = 01X1010X0111100X0110001101XX00X1110X +mem[58804] = 116385 +mem[57709] = 27103 +mem[62492] = 11102 +mem[62031] = 24113 +mem[23580] = 101015510 +mask = 0X110100011110010110111100X11X110X01 +mem[45855] = 345 +mem[33796] = 2069488 +mem[61694] = 409 +mem[42908] = 529 +mem[54356] = 1540 +mem[2931] = 6893 +mem[13629] = 161 +mask = 011X010111111000X11001010XX0100110X1 +mem[48232] = 2748 +mem[46818] = 1360569 +mem[37978] = 59020939 +mem[3596] = 13931 +mask = 011X0101011110X00110110010X11100XX00 +mem[8686] = 3043212 +mem[99] = 1008741 +mem[19665] = 4017 +mem[57438] = 94605425 +mem[55264] = 1505951 +mask = 0010XX11X00X1X000110X0X101X1010000X1 +mem[38124] = 952 +mem[24080] = 109634238 +mem[9221] = 3755102 +mem[6097] = 7229649 +mem[44702] = 6963 +mem[4664] = 75052121 +mem[54208] = 50749 +mask = 001X000100X001000111X0XX101110X0X00X +mem[29210] = 30278 +mem[34588] = 8139931 +mem[4262] = 170 +mem[30822] = 116256036 +mem[35104] = 2105 +mem[53802] = 202809516 +mem[34175] = 11635 +mask = 10110111101X10X01110X0101X1101X1000X +mem[31068] = 8529566 +mem[55554] = 1887440 +mem[43973] = 711 +mem[30117] = 89 +mem[32710] = 6073240 +mask = X11001011100110101X10X0X0X0111010000 +mem[33533] = 67852 +mem[41455] = 2159161 +mem[61283] = 7275538 +mem[26353] = 49998 +mem[37978] = 396 +mem[56038] = 27870483 +mem[48893] = 2558 +mask = 00110X0X10XX1001X101001001010XX10001 +mem[15308] = 3190807 +mem[29791] = 1689321 +mem[23706] = 28489987 +mem[52184] = 13941172 +mask = 0111010111X010X1011011X01110X0X10111 +mem[46818] = 3960 +mem[896] = 8079 +mem[51892] = 10813637 +mem[40539] = 50432 +mem[39200] = 405093301 +mem[59082] = 24044094 +mask = 0X11X00100110X0001111000X10000X01000 +mem[18818] = 115548503 +mem[3709] = 408 +mem[28387] = 1517 +mem[18617] = 82658 +mask = 00100X0001X0100001X010100011X0XX0001 +mem[16645] = 2580 +mem[55034] = 1395 +mem[24779] = 57573 +mask = 010100X11111000010XXXX0X0X1XX0110010 +mem[51498] = 514 +mem[56424] = 27530520 +mem[5657] = 5653 +mem[60013] = 1759 +mem[39685] = 48186 +mask = X0100X0111101XX1111001X101110XXX11X0 +mem[15867] = 15856896 +mem[16645] = 22385 +mem[11204] = 56370 +mask = 0X1X0101X0101000111011110X111010X001 +mem[30186] = 149471 +mem[55297] = 6189241 +mem[56429] = 7551 +mem[35853] = 1943 +mem[50590] = 3973692 +mask = 0111010X011X10XXX100011XX11101X0X011 +mem[41687] = 10091 +mem[27747] = 12073 +mem[41632] = 117 +mem[53319] = 6596158 +mask = 101001011110X1011110001X11111XX01001 +mem[8898] = 350890 +mem[61425] = 11351 +mem[30900] = 62547453 +mem[32345] = 4152907 +mem[53681] = 15100 +mask = 0X10010X1X0110X0011001101001X010XX11 +mem[46274] = 266245793 +mem[51690] = 6210475 +mem[31828] = 50916780 +mem[40159] = 1305075 +mask = X1110X0001XX11001100111111X0100X00X0 +mem[13308] = 2061153 +mem[21134] = 100 +mem[22800] = 43346237 +mem[63215] = 1528 +mem[3115] = 159268 +mem[51760] = 3390 +mask = 011X0101011100000110X1X1X1101X1100X1 +mem[3709] = 1727 +mem[30692] = 4483 +mem[4143] = 22098690 +mem[8978] = 536 +mask = 1X1X01011X10X101X110000X11111010X100 +mem[1983] = 1355679 +mem[18831] = 4847364 +mem[26861] = 6413 +mask = 111XXX10X11010001X10X10X0111100X1X00 +mem[1940] = 622180477 +mem[33455] = 6793 +mem[54070] = 74933929 +mem[1936] = 6134620 +mask = 1X1X010X111011XX1110010100X1X0X01X01 +mem[4347] = 29272422 +mem[26401] = 180116335 +mem[53382] = 684 +mem[29142] = 91826 +mem[30] = 11042 +mem[30490] = 92215 +mask = 11X101111110110011100111X1X11X1001X1 +mem[35424] = 3594 +mem[54399] = 228781216 +mem[33796] = 149514889 +mem[29544] = 697176893 +mem[38146] = 169131 +mem[35144] = 33941748 +mem[39849] = 293 +mask = XX1101XX1X101000111011011110X0100101 +mem[11432] = 76469 +mem[19223] = 5525 +mem[45424] = 201 +mem[3709] = 5622752 +mem[64781] = 8199 +mask = 011001011X1110011111X0X00X1000000101 +mem[54292] = 949 +mem[26880] = 10542 +mem[62098] = 860 +mask = 111X010X111011111X10001X01X100X11001 +mem[22272] = 951175 +mem[20506] = 1133335 +mem[57502] = 177607519 +mask = 01100X0101X1110X01X01101X11XX1X111X0 +mem[30880] = 1070 +mem[25208] = 25110 +mem[29830] = 43106 +mem[44754] = 7361 +mask = 0X1X0101111X100XX11X0100010100X00101 +mem[57107] = 9040 +mem[19968] = 326431400 +mem[30553] = 2988 +mem[1096] = 54078 +mem[5657] = 822343 +mem[24080] = 241413 +mem[54292] = 14129212 +mask = 0X110X010X1XXX00011111X001X010X10000 +mem[43660] = 37456160 +mem[51849] = 1253870 +mask = 111001X0X1X01000111000X00XX00010X000 +mem[11663] = 66023717 +mem[26130] = 503044 +mem[44779] = 44698095 +mem[12702] = 53757 +mem[22414] = 1795507 +mask = 0111X1010111X1X0X1100X010001X0011010 +mem[39200] = 4090252 +mem[31845] = 2782402 +mem[22284] = 429 +mem[29279] = 16254306 +mask = 01010101111X0X000X1011X11XX11X1XX111 +mem[50705] = 1963 +mem[40289] = 71985 +mem[43716] = 411505145 +mem[3338] = 661 +mem[2430] = 2635 |