68bbcb0ce4f7
2020/14
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Tue, 14 Dec 2021 20:18:56 -0500 |
parents | 6614131d7b10 |
children | cec05589a84c |
branches/tags | (none) |
files | data/2020/14.txt src/2020/days/day-14.lisp |
Changes
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/2020/14.txt Tue Dec 14 20:18:56 2021 -0500 @@ -0,0 +1,545 @@ +mask = X00000000000110011100XXX011110111011 +mem[41579] = 225076 +mem[14806] = 26208185 +mem[47659] = 176531392 +mem[27723] = 186971157 +mem[35129] = 3483636 +mem[27142] = 4246 +mask = 01101X10101011000101X1X0XXX101111110 +mem[16685] = 392461 +mem[65343] = 13662482 +mem[53292] = 736 +mem[6830] = 382342975 +mem[12777] = 19983424 +mem[19592] = 679514970 +mem[8776] = 122013 +mask = 011X110100011100111001X1000XX011001X +mem[29076] = 305532 +mem[30139] = 135337 +mask = 0100X00X1010110X0X010010010001000001 +mem[32307] = 2921 +mem[29478] = 15201 +mask = 1X101101001111111XX1XX1X00X100111X11 +mem[35018] = 63654376 +mem[13977] = 22331 +mem[7078] = 27879686 +mem[36409] = 1248 +mem[29098] = 1049 +mask = 010X0001001X111011001011X000X100X010 +mem[37355] = 3525 +mem[37012] = 16715 +mem[2023] = 7212969 +mem[31805] = 455891 +mem[34394] = 411403104 +mem[5056] = 14954425 +mem[55325] = 17658 +mask = 01101XX01010X100010XXX011110111X0010 +mem[60619] = 889 +mem[65362] = 145345 +mem[53540] = 2298570 +mem[62434] = 542 +mem[12457] = 1279 +mem[5456] = 4090 +mask = 01001X01100010101111X000X01X0X01X001 +mem[27104] = 3012 +mem[9008] = 75 +mem[31688] = 60 +mask = XX01X00000XX110011100X0X010110XX1100 +mem[25251] = 7374 +mem[63139] = 27875755 +mem[42967] = 8204614 +mem[61987] = 396 +mem[30866] = 691 +mask = 1001000X00X0110X1110001000100101XX00 +mem[40705] = 21726765 +mem[7454] = 22726 +mem[46834] = 68819 +mem[7078] = 643555271 +mem[48619] = 34299689 +mem[42749] = 27406055 +mem[32511] = 54957378 +mask = 0X0110010011X1X0110000001010000100X0 +mem[5752] = 957 +mem[58252] = 463561556 +mask = 0X1X1X010011110X111001X00001000XX0X0 +mem[63353] = 14516 +mem[15823] = 2060 +mem[30126] = 102554 +mem[30621] = 17543629 +mem[35116] = 76250 +mem[10236] = 11446819 +mem[16660] = 2541872 +mask = 1X01X00000101100X1X01111100101100000 +mem[48609] = 312842 +mem[2909] = 17774 +mem[19872] = 5613 +mem[9985] = 6539455 +mem[63287] = 312743 +mem[40351] = 16889429 +mask = 0111001001111110XXXX0XXXX11100010011 +mem[61065] = 14018 +mem[1689] = 301351825 +mem[31135] = 568 +mask = X10000100010X000111001X0X0010010X00X +mem[29969] = 7096617 +mem[19809] = 862281685 +mem[30350] = 1871 +mem[31001] = 93711152 +mem[13233] = 33263717 +mem[42482] = 579908 +mask = 01X10X0X00X11100110100011X0X0X0X001X +mem[41248] = 7946615 +mem[1829] = 1576 +mem[907] = 21637953 +mem[3566] = 2883 +mem[29687] = 19408 +mem[15657] = 972 +mask = 010100X10001110010X110X01X0111X01010 +mem[53292] = 609 +mem[55550] = 8115727 +mem[834] = 617 +mem[53708] = 498838597 +mem[39044] = 309 +mem[17842] = 5862 +mask = 0100X00010X011X01110X0XX0110000X1101 +mem[32511] = 50674184 +mem[41256] = 996258 +mem[47199] = 1837 +mask = 1101001XXX1X111X10X00X000X011101X101 +mem[9292] = 623250 +mem[45902] = 258279925 +mem[20440] = 172992884 +mem[31688] = 65210 +mem[2288] = 66034927 +mask = 01100101X110X01X11X01100001000X11001 +mem[58893] = 2144468 +mem[5048] = 750616856 +mask = 010110X1001111001100XX0011100101X0X0 +mem[9150] = 4201416 +mem[33664] = 15504 +mem[7218] = 18606957 +mask = 01X1100X0X00110011X0101101111X0X1111 +mem[8003] = 1403 +mem[64683] = 16052434 +mem[17299] = 43327 +mem[13505] = 961 +mem[48609] = 709578 +mem[11582] = 855 +mem[42822] = 3983 +mask = 01101001X01X11X011XX0111110110000101 +mem[30603] = 24703071 +mem[3805] = 775231 +mem[30098] = 230279 +mem[46351] = 5983 +mem[6689] = 3542 +mem[26816] = 121693 +mask = 1X00X0101010010011X1XX0110110011X0X1 +mem[16838] = 192956313 +mem[60531] = 24171693 +mem[22819] = 38459 +mem[26453] = 6160088 +mask = 1X010X000000110X1110100001X0100100X0 +mem[43837] = 22192131 +mem[10090] = 21946 +mask = 01X111000X011100111XX100001100100000 +mem[4306] = 56171106 +mem[50905] = 3399 +mem[36168] = 121097 +mask = 1X010000XXX111001X100X100100X0X001X1 +mem[31394] = 121478 +mem[4906] = 139929 +mem[36356] = 1924 +mask = 1010X010001011X011X011XX11011110X111 +mem[11864] = 29928714 +mem[30866] = 45934 +mem[19873] = 370711 +mask = 0101100000X10110111110X0XXX1XX110X01 +mem[51120] = 65808488 +mem[22318] = 10244125 +mem[26453] = 13126923 +mem[64961] = 3880 +mask = X01011X1001111X1X11XX100010X00111100 +mem[62778] = 126882 +mem[59733] = 1267462 +mem[13740] = 435 +mem[3400] = 8477 +mem[4133] = 116701 +mem[30619] = 231703 +mask = 01000X011010101011110X1000110XX0110X +mem[45164] = 25402465 +mem[9309] = 77050566 +mem[29909] = 706 +mem[27758] = 1319 +mem[6150] = 106196666 +mask = 01X11X0X00X111001110X1XX0001X001001X +mem[14255] = 13708852 +mem[513] = 3790644 +mem[28804] = 395377671 +mem[57953] = 72417 +mem[28725] = 1201 +mem[11750] = 233 +mask = X10100X100111110110X00001X1011010X11 +mem[49595] = 24812 +mem[64152] = 9382 +mem[12122] = 2319571 +mem[42088] = 482 +mask = 1X000XX010100100111100X001110X1000XX +mem[13636] = 524153304 +mem[36450] = 352968 +mem[6260] = 4407821 +mask = 0111000X000101X01XX100X1X1001110X010 +mem[7218] = 94415 +mem[29864] = 5120026 +mem[53070] = 6612 +mem[36573] = 8326010 +mem[1987] = 5992534 +mem[9798] = 11713 +mask = 110000X01010X100111100X01011000XX10X +mem[26267] = 61334 +mem[29687] = 520585578 +mem[11781] = 66211489 +mask = X001X000000111001110X011001X1X100011 +mem[2023] = 805 +mem[7673] = 1711 +mem[9374] = 7545 +mem[45925] = 33575 +mask = 010X000X10101X000011XXX00X1000000000 +mem[30922] = 12722836 +mem[61189] = 510395 +mem[26267] = 38479500 +mask = X0101X0100X11X1110X11110000000X01011 +mem[55014] = 27563943 +mem[46994] = 497673195 +mem[43529] = 80791407 +mem[65052] = 454391739 +mem[30577] = 304 +mask = 0X01000110011X00X10110111100X0X10010 +mem[45248] = 7792707 +mem[6927] = 12193 +mem[60386] = 3927747 +mem[39315] = 4161237 +mask = X001X01000X01100111010101X111X1X0010 +mem[15099] = 17870434 +mem[60] = 32347 +mem[6193] = 412046876 +mem[61561] = 142217182 +mem[25826] = 2073043 +mem[61322] = 14525 +mask = X1X100X0X11111X01XX000000101000X1X01 +mem[4794] = 233038 +mem[29193] = 23211308 +mem[26267] = 10247786 +mem[44728] = 384574 +mem[57840] = 471 +mem[23517] = 507429935 +mem[8408] = 251968 +mask = X1000X010010110X11X100101X1X1101X100 +mem[14979] = 52721 +mem[14121] = 12422 +mem[65343] = 653 +mem[513] = 23189896 +mask = 1101X0X0010X110010100111101000X00XX0 +mem[21511] = 30489818 +mem[63139] = 13245573 +mem[64852] = 762 +mask = XX01100000011100111X11X00100110X0111 +mem[59229] = 47739 +mem[49595] = 31185 +mem[9374] = 11755159 +mem[42415] = 206175 +mask = X1X010X01010X10001X1010100X1X1X10X10 +mem[65383] = 54664 +mem[17412] = 6631 +mem[55994] = 373011 +mem[53672] = 26530655 +mem[7974] = 1007816675 +mask = 1100X010X01X1000111001X100011011000X +mem[4896] = 38031019 +mem[754] = 2287 +mem[30181] = 50259322 +mask = 1X010XX00XX111001X10X110100X10000100 +mem[32551] = 7983378 +mem[7438] = 31324924 +mask = 0101X0000010X100111000X0X1X110X01110 +mem[25209] = 48369038 +mem[50393] = 576369 +mem[40859] = 3812 +mem[56386] = 569373625 +mem[63105] = 8734731 +mask = 10101XX0001011X01110XX001X010110XX0X +mem[34042] = 19350728 +mem[32063] = 255940784 +mem[33476] = 53404 +mem[35243] = 209057823 +mem[4983] = 377086 +mem[4794] = 16200733 +mask = 01X01000101X110001010X11X01X00000101 +mem[19467] = 14126078 +mem[29699] = 830 +mask = 010110X000X1X110111XX1001111X0X10XX1 +mem[43026] = 13471405 +mem[4984] = 1882 +mem[18947] = 15001421 +mask = XX011001X0XXXX001X1101X0000100001010 +mem[55787] = 737 +mem[1563] = 2538 +mem[59758] = 28003877 +mask = 100X000X000X110X1X101100001011X1X011 +mem[25696] = 172112 +mem[12279] = 113288 +mem[24031] = 37612590 +mask = 11XX00X00010110011100101X11010100111 +mem[46130] = 1530 +mem[12542] = 795 +mask = 110X00011X01111001X00X1100100010XX10 +mem[27592] = 128275 +mem[27809] = 132195912 +mem[24738] = 199737 +mem[19162] = 15356 +mask = 010001010X10X10X1111000010001101X000 +mem[8268] = 377409380 +mem[10236] = 540166 +mem[38723] = 139937 +mem[60530] = 7895799 +mem[21813] = 6275543 +mem[8917] = 50534988 +mem[50461] = 251351 +mask = 0110X1011XX01X1011X0X1010X11X000X000 +mem[37937] = 2706 +mem[53672] = 23428 +mem[16637] = 43775004 +mem[13789] = 23884648 +mask = 1X0X00X0001011001110000101X1X1X0X0X1 +mem[55787] = 960988 +mem[29687] = 510439 +mem[63862] = 122580 +mem[30126] = 1488 +mem[44826] = 3558 +mask = XX00001010X011001X110X0X11XX10000X00 +mem[5760] = 209762 +mem[27142] = 2968 +mem[19789] = 269 +mem[634] = 9949 +mask = 01X0X00010101100X1X101XX01110X0X011X +mem[24659] = 304 +mem[28725] = 7064540 +mem[23533] = 396592131 +mem[42715] = 129702313 +mask = 1X0X0000X0X0110011101X10011X1110000X +mem[31688] = 698304069 +mem[28880] = 1648 +mem[1915] = 1894 +mem[50253] = 3317783 +mask = 0101X00100X1110011XX00X00X00X00XX010 +mem[7930] = 49938921 +mem[45686] = 376 +mem[44994] = 394081142 +mem[25475] = 1655 +mem[11478] = 704 +mem[34150] = 4147579 +mask = X10X00X0011X11001X100100011100000011 +mem[13838] = 9047 +mem[64712] = 7762 +mem[63477] = 6690357 +mem[38863] = 7288 +mask = 01000000101011000X11011XX111000X01X1 +mem[20533] = 10736847 +mem[40924] = 430217452 +mem[64360] = 2426851 +mem[58115] = 12071761 +mem[30126] = 26562102 +mem[6672] = 154543 +mem[4382] = 10121 +mask = 01X110X00X1X11101X10X110011100X00011 +mem[20472] = 194 +mem[35111] = 708430742 +mem[2674] = 44 +mem[39452] = 614 +mem[19219] = 110991746 +mask = 01X10X010001X1001XX1X00000X00X000110 +mem[38888] = 996404203 +mem[13988] = 2030 +mem[29687] = 833197 +mask = X0010000X00X11X001X000X001011XX1X001 +mem[19041] = 26558 +mem[57953] = 30524 +mem[58714] = 3716054 +mem[12930] = 83910 +mask = 1101100X0X111X001X10XX1101011X100000 +mem[45686] = 3647 +mem[33541] = 36310663 +mem[17979] = 6056054 +mem[10534] = 16345 +mem[47111] = 232953370 +mem[25533] = 27557895 +mem[58098] = 1560064 +mask = 100X0000X0X011XX11X001000101111X0000 +mem[26199] = 246090059 +mem[18199] = 88594470 +mem[29909] = 16759 +mem[64360] = 634531 +mask = 0101XXX10011110XX1100011000X001101X0 +mem[16673] = 22927535 +mem[12390] = 62487 +mem[60131] = 719 +mem[20196] = 175993 +mem[34150] = 25943355 +mem[9914] = 48537509 +mem[41065] = 46726 +mask = 0101000100X11100XX01000X101001000000 +mem[61353] = 192 +mem[30126] = 122504373 +mem[43978] = 112475 +mem[54606] = 262832639 +mask = 110000X01XX0010X1111011010XX01110100 +mem[38654] = 5670 +mem[19246] = 3500 +mem[3280] = 780682 +mem[25841] = 3675082 +mem[10090] = 939 +mem[30577] = 19385 +mask = 1101X000001X11XX1110010101101X101X01 +mem[30181] = 467224373 +mem[64712] = 19540 +mem[9150] = 110790020 +mem[58763] = 649 +mem[61987] = 31515335 +mem[36168] = 40664 +mask = 011001X1X10010X01X1X0X010100X101X1X1 +mem[50341] = 249123925 +mem[57809] = 1245764 +mem[1000] = 6880 +mem[62447] = 9704635 +mem[57040] = 22401 +mem[36847] = 1403 +mask = 1XX0X01000101XX0111001X00101110XX101 +mem[44459] = 1909253 +mem[28804] = 13248 +mask = 11000000X010X1001110111XX0100X101000 +mem[44826] = 1584 +mem[8549] = 20390300 +mem[8024] = 83478929 +mem[26411] = 1612730 +mem[27809] = 3340355 +mask = 0101100X00X111X0111XX100X010000100X1 +mem[43026] = 246196988 +mem[3889] = 148865 +mem[43538] = 168294874 +mem[37181] = 2452 +mem[13074] = 203182 +mask = 100100100101110011X0XX10X101101XX100 +mem[47655] = 2283 +mem[43365] = 51654102 +mem[20448] = 1899 +mem[46501] = 866 +mem[39220] = 8179259 +mask = 01100101111X11XX1X00X100000X0110XX00 +mem[4063] = 25905 +mem[56197] = 7616 +mem[22101] = 96196611 +mask = XX011100X001110X1110XX000X1010000010 +mem[38766] = 317650050 +mem[275] = 1077 +mem[47272] = 3545 +mem[17513] = 428 +mem[31209] = 10901538 +mem[60020] = 8191405 +mask = 100X0000X0001100X110XXX00001110X000X +mem[3889] = 240406519 +mem[58283] = 105792011 +mem[2023] = 11451400 +mem[42056] = 500252 +mask = 0101100100X11X00110100X001001X0000X0 +mem[51566] = 18992 +mem[2207] = 9397005 +mem[16208] = 18748 +mem[11287] = 117402894 +mem[10310] = 16126 +mem[63935] = 59804 +mask = X1X00X01101011X011XX1001011X10110X01 +mem[17412] = 292 +mem[55917] = 290254 +mem[36766] = 38849561 +mem[39220] = 401237793 +mask = 011001011X1011X01X100001000110010X00 +mem[41854] = 1014518 +mem[16822] = 16372 +mem[36517] = 6130231 +mem[37271] = 406796637 +mask = 0X01000X000111X0111X011001X000000X11 +mem[58255] = 95641 +mem[98] = 61432470 +mask = 0100000100101XX01111100100X11X011101 +mem[9985] = 1592325 +mem[11478] = 2271665 +mem[3757] = 41068007 +mem[61585] = 70572 +mem[17154] = 335361 +mem[60531] = 41930933 +mask = 1001X00000X011011110X0100X000X010010 +mem[64462] = 29767556 +mem[24738] = 210929 +mem[50899] = 1287 +mask = 000XX000000111100100X10001X10010100X +mem[6334] = 287 +mem[34777] = 1860550 +mask = 110X001000101X001110X111010X0X1X0X01 +mem[12157] = 6178 +mem[40351] = 59493 +mem[30619] = 34292339 +mem[13636] = 1290347 +mask = X100000XX01011X0111X100101000X10X1X1 +mem[60731] = 9983015 +mem[9985] = 18414272 +mem[56154] = 62268050 +mem[40924] = 15580622 +mask = 01010001XX011100110110100X00XX010000 +mem[24823] = 113683 +mem[33142] = 14761835 +mem[33664] = 26275 +mem[7822] = 5148968 +mem[39411] = 1216069 +mem[27779] = 102128 +mem[36065] = 10811 +mask = 11X00010XX10100011X00001X11X0X1X10X1 +mem[34192] = 592942932 +mem[61987] = 27192613 +mem[63760] = 8016 +mask = 010XX00110X01X101111100X0X100X100001 +mem[14125] = 363398 +mem[9080] = 113944 +mem[29909] = 14606451 +mem[52829] = 102953 +mask = 0101XX01001111X0110X0010XX0001011110 +mem[8212] = 2171 +mem[60531] = 439001 +mem[11151] = 8267 +mem[634] = 51725 +mem[38040] = 6915656 +mask = XX01001X011X1X001000011100100X000101 +mem[18184] = 34766 +mem[53526] = 38417257 +mem[28494] = 114210018 +mem[102] = 3422103 +mask = X100000010101100X1110XXX01110000X1X1 +mem[7454] = 3185 +mem[45157] = 3488 +mem[62822] = 3659366 +mask = 1110100X1010110001X1X11X1001X0X1001X +mem[58002] = 236109549 +mem[3536] = 11719 +mem[40939] = 550805420 +mem[34751] = 538 +mem[51410] = 19066 +mem[11996] = 29329688 +mask = 01010XX00001111011X00110010X0010X111 +mem[64654] = 1185760 +mem[56361] = 13297936 +mem[102] = 3966 +mem[18335] = 470391 +mem[1905] = 25790 +mask = X10X000110XX1110X11001000X00101001X0 +mem[55089] = 17943368 +mem[40456] = 501700825 +mem[47927] = 513748 +mem[13838] = 385
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/2020/days/day-14.lisp Tue Dec 14 20:18:56 2021 -0500 @@ -0,0 +1,62 @@ +(advent:defpackage* :advent/2020/14) +(in-package :advent/2020/14) + +(defun parse (stream) + (iterate + (for line :in-stream stream :using #'read-line) + (collect (or (ppcre:register-groups-bind ((#'parse-integer addr val)) + ("mem\\[(\\d+)\\] = (\\d+)" line) + (list :set addr val)) + (ppcre:register-groups-bind (mask) + ("mask = ([X01]+)" line) + (list :mask mask)))))) + +(defun op (inst) (first inst)) +(defun mask (inst) (second inst)) +(defun addr (inst) (second inst)) +(defun value (inst) (third inst)) + +(defun-inline char->bit (char) + (ecase char (#\0 0) (#\1 1))) + +(defun-inline dpbit (bit pos value) + (dpb bit (byte 1 pos) value)) + +(defun mask-value (mask value) + (iterate (for char :in-string mask :downto 0) + (for pos :from 0) + (unless (eql #\X char) + (setf value (dpbit (char->bit char) pos value)))) + value) + +(defun mask-address (mask addr) + (iterate (with-result addrs = (list addr)) + (for pos :from 0) + (for char :in-string mask :downto 0) + (ecase char + (#\X (setf addrs (append (mapcar (curry #'dpbit 0 pos) addrs) + (mapcar (curry #'dpbit 1 pos) addrs)))) + (#\0 (progn)) + (#\1 (map-into addrs (curry #'dpbit 1 pos) addrs))))) + +(defun run-program (program &key part) + (iterate (with memory = (make-hash-table)) + (with mask = nil) + (for inst :in program) + (ecase (op inst) + (:mask (setf mask (mask inst))) + (:set (ecase part + (1 (setf (gethash (addr inst) memory 0) + (mask-value mask (value inst)))) + (2 (dolist (addr (mask-address mask (addr inst))) + (setf (gethash addr memory 0) + (value inst))))))) + (finally (return (reduce #'+ (alexandria:hash-table-values memory)))))) + +(define-problem (2020 14) (data parse) (9967721333886 4355897790573) + (values + (run-program data :part 1) + (run-program data :part 2))) + + +#; Scratch --------------------------------------------------------------------