Skip to content

Instantly share code, notes, and snippets.

@Stevie-O
Created December 19, 2024 05:54
Show Gist options
  • Save Stevie-O/01f043c9e2ac50715caa0b7b06474ee5 to your computer and use it in GitHub Desktop.
Save Stevie-O/01f043c9e2ac50715caa0b7b06474ee5 to your computer and use it in GitHub Desktop.
AOC 2024 Day 17 Solver - Intcode

AOC 2024 Day 17 Intcode solver

USAGE

All input and output is done in ASCII. Attempts to ignore CRs ('\r' aka 0x0D aka 015).

Input must exactly conform to the example and puzzle inputs supplied for Day 17.

Input may be terminated as follows:

  • Newline after last program code digit.
  • NUL (0x00) after last program code digit.
  • A negative number (i.e. the EOF returned by fgetc).

Outputs two lines. First line is part 1 answer (program output with supplied register values). Second line is the part 2 answer (smallest initial value for register A that creates a quine.)

1101,0,0,3,109,2302,1101,13,0,1339,1105,1,1298,3,30,1007,30,48,20,1105,0,1859,107,55,30,27,1105,0,1859,21101,0,-48,0,109,1,1001,2301,1,2301,203,0,1208,0,44,46,1105,0,13,1208,0,13,53,1105,0,39,1208,0,10,60,1105,0,72,2107,0,0,67,1106,0,72,1105,1,1859,21101,0,0,0,109,1,21001,2033,0,1,21001,2029,0,2,21101,93,0,0,1105,1,1659,1201,1,0,2034,21001,2035,0,1,21001,2030,0,2,21101,112,0,0,1105,1,1659,1201,1,0,2036,21001,2037,0,1,21001,2031,0,2,21101,131,0,0,1105,1,1659,1201,1,0,2038,1008,1,2,140,1106,0,193,21001,2033,0,1,21001,2034,0,2,21101,157,0,0,1105,1,1760,204,1,21001,2035,0,1,21001,2036,0,2,21101,174,0,0,1105,1,1760,204,1,21001,2037,0,1,21001,2038,0,2,21101,191,0,0,1105,1,1760,204,1,21101,523,0,1,21101,204,0,0,1105,1,794,104,10,1005,1,473,21101,216,0,0,1105,1,227,1206,1,1845,21101,226,0,0,1105,1,1564,99,109,1,21001,2301,-1,1,20101,2302,2301,2,21201,2,-1,2,20101,2045,2028,3,21101,0,0,4,21101,256,0,0,1105,1,265,21201,1,0,0,109,-1,2105,1,0,109,8,21201,-5,-3,-5,21101,0,0,-3,1205,-4,282,21201,-3,1,-3,21201,-5,0,1,21201,-3,0,2,21101,297,0,0,1105,1,1659,21201,1,0,-2,1206,-4,334,1208,-2,3,309,1105,0,334,2201,-5,-2,318,1101,0,0,0,1001,318,1,318,21201,-2,1,-2,1207,-2,3,332,1105,0,315,21201,-4,0,-1,22201,-4,-2,-4,1201,-5,0,2033,1201,-4,0,2034,1101,0,0,2036,1101,0,0,2038,1201,-6,0,2044,21101,454,0,1,21101,373,0,0,1105,1,794,1206,1,423,1205,-7,397,21201,-5,0,1,21201,-4,0,2,21101,394,0,0,1105,1,1760,1105,1,445,21201,-7,-1,1,21201,-6,-1,2,21201,-5,0,3,21201,-4,0,4,21101,420,0,0,1105,1,265,1205,1,445,21201,-1,0,-4,21201,-3,1,-3,1207,-3,8,436,1105,0,282,21101,0,0,-7,1105,1,449,21201,1,0,-7,109,-8,2105,1,0,109,2,1001,2044,0,466,1001,2044,1,2044,20208,-1,0,-1,109,-2,2105,1,0,104,65,104,58,104,32,21001,2033,0,1,21001,2034,0,2,21101,494,0,0,1105,1,1760,21101,501,0,0,1105,1,1564,104,10,1001,474,1,474,1001,480,2,480,1001,484,2,484,1001,520,-1,520,1105,3,473,99,109,2,1106,0,530,104,44,21201,-1,48,-1,204,-1,1101,1,0,526,21101,1,0,-1,109,-2,2105,1,0,109,1,1006,2041,593,1001,2035,0,567,1001,2042,0,569,1001,2036,0,583,1001,0,0,0,1001,567,1,567,1001,569,1,569,1001,583,-1,583,1105,0,566,1001,2042,0,2035,1101,0,0,2041,109,-1,2105,1,0,109,1,1001,2038,0,2040,1006,2038,638,1001,2037,0,620,1001,2043,0,622,1001,2038,0,636,1001,0,0,0,1001,620,1,620,1001,622,1,622,1001,636,-1,636,1105,0,619,1001,2043,0,2039,109,-1,2105,1,0,109,2,21101,656,0,0,1005,2041,549,7,2036,2040,661,1106,0,699,21001,2035,0,-1,1001,2039,0,2035,1201,-1,0,2039,21001,2036,0,-1,1001,2040,0,2036,1201,-1,0,2040,21001,2042,0,-1,1001,2043,0,2042,1201,-1,0,2043,109,-2,2105,1,0,109,3,21101,713,0,0,1105,1,647,1006,2040,789,7,2040,2036,783,21101,0,0,-2,21101,0,0,-1,1001,2040,0,780,1001,2035,0,745,1001,2035,0,751,1001,2039,0,746,8,0,0,749,1108,0,0,0,21201,-1,1,-1,1001,745,1,745,1001,751,1,751,1001,746,1,746,1005,749,775,21201,-1,0,-2,1001,780,-1,780,1105,0,744,1105,0,789,1201,-2,0,2036,109,-3,2105,1,0,109,4,1101,0,0,2032,1101,1,0,1092,1101,999999,0,813,1001,813,-1,813,1106,0,1873,7,2032,2301,820,1106,0,1263,101,2302,2032,827,21001,0,0,-2,1001,2032,1,2032,101,2302,2032,839,21001,0,0,-1,1001,2032,1,2032,2107,3,-1,851,1106,0,960,1208,-2,1,858,1105,0,960,1208,-2,3,865,1105,0,960,1208,-2,4,872,1105,0,960,2107,6,-1,879,1105,0,1866,21201,-1,-4,-1,1208,-2,2,890,1105,0,1108,21202,-1,2,-1,2101,2033,-1,905,1001,905,1,909,21001,0,0,1,21001,0,0,2,1207,2,4,917,1105,0,938,1208,-2,2,928,1208,-2,5,929,1101,0,0,932,1106,0,938,21101,3,0,2,21101,945,0,0,1105,1,1760,21201,1,0,-1,1105,1,960,967,1212,1159,1077,1249,1056,1000,1030,2101,952,-2,966,105,1,0,2007,2034,-1,972,1106,0,978,21001,2034,0,-1,1206,-1,808,2001,2033,-1,2033,21202,-1,-1,-1,2001,2034,-1,2034,1101,1,0,1092,1105,1,808,2007,2034,-1,1005,1106,0,1011,21001,2034,0,-1,1101,1,0,2041,2001,2033,-1,2035,21202,-1,-1,-1,2001,2034,-1,2036,1105,1,808,2007,2034,-1,1035,1106,0,1041,21001,2034,0,-1,2001,2033,-1,2037,21202,-1,-1,-1,2001,2034,-1,2038,1105,1,808,21201,-1,0,1,21101,1067,0,0,2105,1,-3,1205,1,808,21201,1,0,-3,1105,1,1267,1006,2034,808,1001,2032,-2,1085,2107,0,-1,1089,1105,0,1098,1106,1,1873,1101,0,0,1092,1201,-1,0,2032,1105,1,808,1115,1145,1130,2101,1105,-1,1114,105,1,0,1101,1,0,2041,1001,2033,0,2035,1001,2034,0,2036,1105,1,1145,1101,1,0,2041,1001,2037,0,2035,1001,2038,0,2036,1105,1,1145,107,3,2036,1150,1106,0,808,1101,3,0,2036,1105,1,808,1001,2042,0,2035,1101,0,0,2036,1206,-1,808,2107,1,-1,2036,1001,2036,1,2036,1001,2035,0,1193,1208,-1,2,1191,1008,1191,0,1191,1101,0,0,0,1008,2036,1,1199,1105,0,808,1001,2035,1,1208,1101,1,0,0,1105,1,808,21101,1219,0,0,1005,2041,549,1001,2043,0,2039,21001,2043,0,1,21201,-1,0,2,21101,1238,0,0,1105,1,1659,1201,1,0,2040,21101,808,0,0,1105,1,704,21101,1256,0,0,1105,1,598,21101,808,0,0,1105,1,704,21101,1,0,-3,109,-4,2105,1,0,82,101,103,105,115,116,101,114,32,65,58,32,0,80,114,111,103,114,97,109,58,32,0,0,0,0,1101,1272,0,1311,1101,0,0,1297,1101,0,0,1390,1001,0,0,1295,1006,1295,1333,3,1296,8,1295,1296,1324,1106,0,1859,1001,1311,1,1311,1105,1,1310,1008,1311,1294,1338,1105,0,1852,3,1296,1008,1296,13,1347,1105,0,1340,1008,1296,10,1354,1105,0,1389,1007,1296,48,1361,1105,0,1859,107,57,1296,1368,1105,0,1859,1101,1,0,1390,101,-48,1296,1296,1002,1297,10,1297,1,1297,1296,1297,1105,1,1340,1106,0,1859,1001,1297,0,2029,1001,1395,1,1395,1001,1281,1,1281,107,67,1281,1409,1106,0,1298,3,1296,1008,1296,13,1418,1105,0,1411,1008,1296,10,1425,1106,0,1859,1101,1285,0,1311,1105,1,1310,1435,109,8,21101,0,0,-3,1201,-7,0,1513,1101,1449,0,1524,21101,0,0,-4,21101,0,0,-2,203,-1,1208,-1,10,1464,1105,0,1489,1207,-1,48,1471,1105,0,1480,2107,57,-1,1478,1106,0,1525,1205,-5,1457,1206,-2,1457,1105,1,1503,2201,-3,-2,1494,1106,0,1457,1206,-2,1555,1101,1555,0,1524,2007,1513,-6,1508,1106,0,1852,1201,-4,0,0,101,1,1513,1513,22101,1,-3,-3,1105,1,1449,1201,-4,0,1546,22101,1,-2,-2,22101,-48,-1,-1,22102,10,-4,-4,22201,-4,-1,-4,2107,0,-4,1550,1106,0,1838,1105,1,1457,21201,-3,0,-7,109,-8,2105,1,0,109,2,1206,-1,1587,21201,-1,0,1,21101,1,0,2,21101,1584,0,0,1105,1,1594,1105,1,1589,104,48,109,-2,2105,1,0,109,5,21201,-4,0,1,2207,-4,-3,1605,1105,0,1650,21202,-3,10,2,21101,1618,0,0,1105,1,1594,21201,1,0,-4,21202,-3,-1,-1,21101,48,0,-2,2207,-4,-3,1635,1105,0,1648,21201,-2,1,-2,22201,-4,-1,-4,1105,1,1630,204,-2,21201,-4,0,-4,109,-5,2105,1,0,21101,1,0,3,21001,2028,0,4,1105,1,1670,109,6,21101,0,0,-1,2207,-4,-3,1681,1105,0,1751,1206,-2,1838,2207,-3,-4,1691,1106,0,1724,22101,1,-5,1,21201,-4,0,2,21202,-3,2,3,21201,-2,-1,4,21101,1716,0,0,1105,1,1670,22201,-1,1,-1,21201,2,0,-4,1201,-5,0,1735,2207,-4,-3,1733,1108,0,0,0,21201,-1,1,-1,1005,1733,1751,1202,-3,-1,1749,21201,-4,0,-4,21201,-1,0,-5,109,-6,2105,1,0,109,4,1201,-3,0,1778,21101,0,0,-3,21101,1,0,-1,1206,-2,1800,2002,0,-1,1783,21201,-3,0,-3,21202,-1,2,-1,1001,1778,1,1778,21201,-2,-1,-2,1205,-2,1777,109,-4,2105,1,0,0,0,0,1001,1805,0,1813,1001,0,0,1806,101,1,1805,1821,1001,0,0,1807,1001,1821,1,1821,4,1807,1001,1806,-1,1806,1005,1806,1820,99,1101,1880,0,1805,1105,1,1808,1101,1907,0,1805,1105,1,1808,1101,1934,0,1805,1105,1,1808,1101,1950,0,1805,1105,1,1808,1101,1969,0,1805,1105,1,1808,1101,2002,0,1805,1105,1,1808,26,73,110,116,101,103,101,114,32,111,118,101,114,102,108,111,119,32,100,101,116,101,99,116,101,100,10,26,85,110,115,111,108,118,97,98,108,101,32,105,110,112,117,116,32,100,101,116,101,99,116,101,100,10,15,73,110,116,101,114,110,97,108,32,101,114,114,111,114,10,18,73,110,112,117,116,32,112,97,114,115,101,32,101,114,114,111,114,10,32,73,110,118,97,108,105,100,32,111,112,99,111,100,101,32,111,114,32,99,111,109,98,111,32,111,112,101,114,97,110,100,10,23,73,110,102,105,110,105,116,101,32,108,111,111,112,32,100,101,116,101,99,116,101,100,10,2,523,64,0,0,0,0,2045,0,2173,0,2109,0,2237,0,0,2173,2237,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment