From 8e419e5f33129fae84965a39e6f3f4338e15f6d9 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Wed, 23 Dec 2015 09:54:37 +0000 Subject: [PATCH] Day 23 --- SIGNED.md | 31 ++--- advent-of-code-23.html | 150 +++++++++++++++++++++++ advent22.ipynb | 264 ++++++++++++++++++++++++++++++++++------- advent23.ipynb | 230 +++++++++++++++++++++++++++++++++++ advent23.txt | 47 ++++++++ 5 files changed, 664 insertions(+), 58 deletions(-) create mode 100644 advent-of-code-23.html create mode 100644 advent23.ipynb create mode 100644 advent23.txt diff --git a/SIGNED.md b/SIGNED.md index 8335e78..5b357c8 100644 --- a/SIGNED.md +++ b/SIGNED.md @@ -3,19 +3,19 @@ -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 -iQIcBAABCAAGBQJWeTulAAoJEJPB2e07PgbqQswP/0s/iRr+GK90BD6KAbd3ni5J -Q0ih6b1dWRtLkpBBGzajjlKFt9xoygVjV2CjiH/f2bYH+GJQToT3QBOTRGr+7lC1 -s9UhGmFkHvZC9B2bG9Y/5D15/LCZFONMWJ23HyfIMKUNY4nX5zPf0zje7wbkSj1h -jdZBrTS9I2UVrA6JT5beKUy0m8fih+WpdlsIV+fbc3TmXgRNwJ5gTtVg8vV2H3SY -X8cZOYfV2cnhqQxqRclRdncypZNcpRC1vyLja2imchHVaDOB741LD42EZi6gOidH -4WhlROqWDfdRZI4/Xk4Ugpq33OyjK95Ag75jOX1tt2vUYouZlHortIZArzjT29R/ -nR2F1tY+r8zwy6x03YKtb/bWn1zbgzp8XWFKl6qwDIMOuQEJru8u7foREJRAcESt -A7PaOpy1YGD908/1Bc1vwvdWenUKlviRULWJoQUuCGmAkI2Ri9CfEEZxcK7pXmZl -Kkj47XnXLXz+jtBiGG0aj+dt6wbKBOqbXY7eU3CZW5zInQAhEp01I4jcAFTIeuE8 -0Kco/OeDiocDshPfjBLhffakipP9J5bmg8fiIEAU2p+d/4nYmH5neoVxq1WXrSa6 -p6CCTU5DVmueiDg9Ohi+597vD1ylXYEAfzbQaWiQj2N/6Ghe1qwdRYV9omX2l2Wo -jay9FFBiKYx5GtYn86O3 -=qQcY +iQIcBAABCAAGBQJWem9kAAoJEJPB2e07PgbqXbEP/i+Et9fESLyxCAVENqKQ33kc +Jy4uadsQxVzW2LJJeSwvRDVmnxldBuTC+bS72SusNGDP7OcEs75JeKmo1E6xSmJJ +idh0u1d2hKsSlqn1WssrIipW8QjzRE/xPCNI5i0Pso3JMFDx7z1/yfGWDq9BcKk9 +4lG4utqsxe5O8OIkBcb4Fxy+nhsqUQb3WGdt+y0ODGZAqaELsSX0lkNOUhz35foR +/ZNwvay6YHW3hk/+GO+4Bs5oqy1YDL5rDDtv6ov55dGIL/Vfel0bOcFldrcvH6KD +oxX71Vd+3ic8GkMllYNZQIn9wYkNEF6ygFQ7UOBC3t75xS7XtaTJIRjqoaXOTD4c +Fj1pt0nRaMac3TPT+7DG6o4TKmQqGHEpos3m6ubE9mWVldVHUKj3kBZ+P1qv4j4j +GSCg3BKNbyU4umNtrmAWoijAX9nB6djwPg5DOy+WR01JlhhVpwUiuqmahunnYNqc +/MljQi/aE3D4vrb+nrViw1JItuHrcjjSritVkttsukNxZ23z1L8rQ4DCmBjav1H6 +tKKSgxQcTncCGRZlAB5e0KIa2dkUvn0Itt3BBGV+ASWULYRaK9Kn3edt627pbZbo +AqVytWEI+yEHP20w9Gx8DRILu0ceXLI8yq2/6PkjNgk4/FTmVSRVIeH6zecKRlq2 +GLqISlGsKEU+5IwHAUjK +=AHmD -----END PGP SIGNATURE----- ``` @@ -56,6 +56,7 @@ size exec file contents 6387 advent-of-code-20.html 3ec26a7cfb58a168b62781f097ebdb71ae3224cadde49588463370faaa3d33f9 7780 advent-of-code-21.html 877675e47121bd4812ab461fd7cd6124c397669a5e6f35c3f19b023728976970 10190 advent-of-code-22.html cb57ad829bd31e59807f3f0ecc95c603eb85b2d9f9e5cbf9432e80283b689298 +6910 advent-of-code-23.html fff58431db66635a7dc9b537f3d0d87a10ac9b20acd6fcb9cf5f8c99e6f40f39 109395 advent-of-code.ipynb 7292eeb9a8019f6931037c70105ab96bf691074dbe963736b6429cb4d4373f51 25607 advent01.ipynb c33ad39a77803a6870dd74998da98e3bb9c2c2db37c34167b330a01d663717e7 7001 advent01.txt 79312922877bdedd09ce0886a42b3d7f7ed092e2218579fb7d6ac1cb38cedebe @@ -96,7 +97,9 @@ size exec file contents 3377 advent20.ipynb be9db2beee6805ac9db9f2dc145abba3275964e36e21580122bacd8436777a30 9373 advent21.ipynb 70f49b67c911f9316c6be1404b57c76bd0b8aca94e16dd6fc1e5b39d3442b2b4 35 advent21.txt 6c4c3bcec0bf45ee485c7595a6a5eb2ad7722bdecf275780e1cdb9993eb931d8 -21424 advent22.ipynb 8b8aac9e511209cba4637523266f00f40be7ac70eec6d1f4dd0d0b50cb64dd3f +25431 advent22.ipynb 7eb725b13c6fc2bdadb19307330615761c297ec7bb3433cd9e3dd1da41dc940e +4882 advent23.ipynb fc19cc164aa4d5ddd0a8cbe930f09bd893612dae5b1a3b73b4579db9e2d41fe0 +298 advent23.txt 780557c20cbab27946114d4cf04359045dd76b6bfdb28b5bde2e1ceb2c520173 ``` #### Ignore diff --git a/advent-of-code-23.html b/advent-of-code-23.html new file mode 100644 index 0000000..69cc5d2 --- /dev/null +++ b/advent-of-code-23.html @@ -0,0 +1,150 @@ + + + + +Day 23 - Advent of Code + + + + + + +

Advent of Code

Neil Smith 46*
+ + + +
+

--- Day 23: Opening the Turing Lock ---

Little Jane Marie just got her very first computer for Christmas from some unknown benefactor. It comes with instructions and an example program, but the computer itself seems to be malfunctioning. She's curious what the program does, and would like you to help her run it.

+

The manual explains that the computer supports two registers and six instructions (truly, it goes on to remind the reader, a state-of-the-art technology). The registers are named a and b, can hold any non-negative integer, and begin with a value of 0. The instructions are as follows:

+
    +
  • hlf r sets register r to half its current value, then continues with the next instruction.
  • +
  • tpl r sets register r to triple its current value, then continues with the next instruction.
  • +
  • inc r increments register r, adding 1 to it, then continues with the next instruction.
  • +
  • jmp offset is a jump; it continues with the instruction offset away relative to itself.
  • +
  • jie r, offset is like jmp, but only jumps if register r is even ("jump if even").
  • +
  • jio r, offset is like jmp, but only jumps if register r is 1 ("jump if one", not odd).
  • +
+

All three jump instructions work with an offset relative to that instruction. The offset is always written with a prefix + or - to indicate the direction of the jump (forward or backward, respectively). For example, jmp +1 would simply continue with the next instruction, while jmp +0 would continuously jump back to itself forever.

+

The program exits when it tries to run an instruction beyond the ones defined.

+

For example, this program sets a to 2, because the jio instruction causes it to skip the tpl instruction:

+
inc a
+jio a, +2
+tpl a
+inc a
+
+

What is the value in register b when the program in your puzzle input is finished executing?

+
+

Your puzzle answer was 307.

--- Part Two ---

The unknown benefactor is very thankful for releasi-- er, helping little Jane Marie with her computer. Definitely not to distract you, what is the value in register b after the program is finished executing if register a starts as 1 instead?

+
+

Your puzzle answer was 160.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also + this puzzle.

+
+ + + + + + diff --git a/advent22.ipynb b/advent22.ipynb index f08ab26..874ce4d 100644 --- a/advent22.ipynb +++ b/advent22.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "metadata": { "collapsed": true }, @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 2, "metadata": { "collapsed": false }, @@ -48,7 +48,7 @@ " {'mana': 101}]}]" ] }, - "execution_count": 7, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -65,7 +65,7 @@ }, { "cell_type": "code", - "execution_count": 153, + "execution_count": 3, "metadata": { "collapsed": false }, @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": 154, + "execution_count": 4, "metadata": { "collapsed": true }, @@ -99,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 155, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -116,7 +116,7 @@ " 'spent': 53}" ] }, - "execution_count": 155, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -127,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": 156, + "execution_count": 6, "metadata": { "collapsed": false }, @@ -144,7 +144,7 @@ " 'spent': 0}" ] }, - "execution_count": 156, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -155,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": 157, + "execution_count": 7, "metadata": { "collapsed": false }, @@ -183,7 +183,7 @@ " 'spent': 286}" ] }, - "execution_count": 157, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -195,9 +195,9 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 37, "metadata": { - "collapsed": true + "collapsed": false }, "outputs": [], "source": [ @@ -212,6 +212,8 @@ " for status in state['ongoing']:\n", " if s in status[0]:\n", " add_this_spell = False\n", + " if spell['name'] == 'Magic missile' and state['cast'] and state['cast'][-1] == 'Drain':\n", + " add_this_spell = False\n", " if add_this_spell:\n", " valid_spells += [spell]\n", " return valid_spells" @@ -219,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 57, "metadata": { "collapsed": false }, @@ -254,7 +256,7 @@ " {'mana': 101}]}]" ] }, - "execution_count": 98, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -265,7 +267,7 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": 58, "metadata": { "collapsed": false }, @@ -293,7 +295,7 @@ " 'spent': 286}" ] }, - "execution_count": 158, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -306,7 +308,7 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": 59, "metadata": { "collapsed": false }, @@ -318,7 +320,7 @@ " {'boss_hp': -2, 'cost': 73, 'name': 'Drain', 'pc_hp': 2}]" ] }, - "execution_count": 159, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -329,7 +331,54 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 60, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'boss_hp': -2, 'cost': 73, 'name': 'Drain', 'pc_hp': 2}]" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s4 = cast_spell(spells[1], s3)\n", + "valid_spells(spells, s4)" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'boss_hp': -4, 'cost': 53, 'name': 'Magic missile'},\n", + " {'boss_hp': -2, 'cost': 73, 'name': 'Drain', 'pc_hp': 2}]" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s4 = cast_spell(spells[0], s3)\n", + "valid_spells(spells, s4)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, "metadata": { "collapsed": true }, @@ -344,7 +393,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 13, "metadata": { "collapsed": true }, @@ -364,7 +413,7 @@ }, { "cell_type": "code", - "execution_count": 160, + "execution_count": 44, "metadata": { "collapsed": false }, @@ -391,7 +440,7 @@ " 'spent': 286}" ] }, - "execution_count": 160, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -402,7 +451,7 @@ }, { "cell_type": "code", - "execution_count": 161, + "execution_count": 45, "metadata": { "collapsed": false }, @@ -424,7 +473,7 @@ " 'spent': 173}" ] }, - "execution_count": 161, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -438,7 +487,7 @@ }, { "cell_type": "code", - "execution_count": 162, + "execution_count": 46, "metadata": { "collapsed": false }, @@ -456,7 +505,7 @@ " 'spent': 226}" ] }, - "execution_count": 162, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } @@ -470,7 +519,7 @@ }, { "cell_type": "code", - "execution_count": 163, + "execution_count": 47, "metadata": { "collapsed": false }, @@ -488,7 +537,7 @@ " 'spent': 229}" ] }, - "execution_count": 163, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -502,7 +551,7 @@ }, { "cell_type": "code", - "execution_count": 164, + "execution_count": 48, "metadata": { "collapsed": false }, @@ -521,7 +570,7 @@ " 'spent': 342}" ] }, - "execution_count": 164, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } @@ -535,7 +584,7 @@ }, { "cell_type": "code", - "execution_count": 165, + "execution_count": 49, "metadata": { "collapsed": false }, @@ -553,7 +602,7 @@ " 'spent': 415}" ] }, - "execution_count": 165, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -567,7 +616,7 @@ }, { "cell_type": "code", - "execution_count": 166, + "execution_count": 50, "metadata": { "collapsed": false }, @@ -590,7 +639,7 @@ " 'spent': 588}" ] }, - "execution_count": 166, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -604,7 +653,7 @@ }, { "cell_type": "code", - "execution_count": 167, + "execution_count": 51, "metadata": { "collapsed": false }, @@ -622,7 +671,7 @@ " 'spent': 641}" ] }, - "execution_count": 167, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -636,7 +685,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 22, "metadata": { "collapsed": true }, @@ -654,7 +703,7 @@ }, { "cell_type": "code", - "execution_count": 125, + "execution_count": 23, "metadata": { "collapsed": false }, @@ -666,7 +715,7 @@ }, { "cell_type": "code", - "execution_count": 186, + "execution_count": 30, "metadata": { "collapsed": false }, @@ -692,7 +741,7 @@ " 'spent': 1269}" ] }, - "execution_count": 186, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -728,6 +777,111 @@ "current_state" ] }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(1587, 2908)" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(agenda), len(closed)" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'armour': 0,\n", + " 'boss_damage': 9,\n", + " 'boss_hp': 0,\n", + " 'cast': ['Poison',\n", + " 'Recharge',\n", + " 'Shield',\n", + " 'Poison',\n", + " 'Drain',\n", + " 'Recharge',\n", + " 'Poison',\n", + " 'Magic missile',\n", + " 'Magic missile'],\n", + " 'mana': 241,\n", + " 'ongoing': [[{'boss_hp': -3}, {'boss_hp': -3}]],\n", + " 'pc_hp': 1,\n", + " 'spent': 1269}" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "agenda = [initial_state]\n", + "closed = []\n", + "while agenda:\n", + " current_state = agenda[0]\n", + " new_states = []\n", + " # print(current_state)\n", + " if victory(current_state):\n", + " # return current_state\n", + " break\n", + " for spell in valid_spells(spells, current_state):\n", + " s2 = cast_spell(spell, current_state)\n", + " if victory(s2):\n", + " new_states += [s2]\n", + " else:\n", + " s3 = boss_turn(s2)\n", + " if victory(s3):\n", + " new_states += [s3]\n", + " if not finished(s3):\n", + " new_states += [apply_ongoing(s3)]\n", + " # print(new_states)\n", + " states_to_add = [s for s in new_states \n", + " if len(s['cast']) <= 50]\n", + " agenda = sorted(states_to_add + agenda[1:], key=lambda s: s['spent'])\n", + " # agenda = new_states + agenda[1:]\n", + "current_state" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(165616, 0)" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(agenda), len(closed)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -737,7 +891,7 @@ }, { "cell_type": "code", - "execution_count": 182, + "execution_count": 25, "metadata": { "collapsed": true }, @@ -751,7 +905,7 @@ }, { "cell_type": "code", - "execution_count": 185, + "execution_count": 32, "metadata": { "collapsed": false }, @@ -777,7 +931,7 @@ " 'spent': 1309}" ] }, - "execution_count": 185, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -814,6 +968,28 @@ "current_state" ] }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(872, 2354)" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(agenda), len(closed)" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/advent23.ipynb b/advent23.ipynb new file mode 100644 index 0000000..371f02e --- /dev/null +++ b/advent23.ipynb @@ -0,0 +1,230 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[['jio', 'a, +18'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['tpl', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['tpl', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['jmp', '+22'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['inc', 'a'],\n", + " ['tpl', 'a'],\n", + " ['jio', 'a, +8'],\n", + " ['inc', 'b'],\n", + " ['jie', 'a, +4'],\n", + " ['tpl', 'a'],\n", + " ['inc', 'a'],\n", + " ['jmp', '+2'],\n", + " ['hlf', 'a'],\n", + " ['jmp', '-7']]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "program = [i.strip().split(' ', 1) for i in open('advent23.txt').readlines()]\n", + "program" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "registers = {'a': 0, 'b': 0, 'pc': 0}" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def hlf(args):\n", + " registers[args] >>= 1\n", + " registers['pc'] += 1\n", + " \n", + "def tpl(args):\n", + " registers[args] *= 3\n", + " registers['pc'] += 1\n", + "\n", + "def inc(args):\n", + " registers[args] += 1\n", + " registers['pc'] += 1\n", + "\n", + "def jmp(args):\n", + " registers['pc'] += int(args)\n", + "\n", + "def jie(args):\n", + " r, o = args.split(', ')\n", + " if registers[r] % 2 == 0:\n", + " registers['pc'] += int(o)\n", + " else:\n", + " registers['pc'] += 1\n", + "\n", + "def jio(args):\n", + " r, o = args.split(', ')\n", + " if registers[r] == 1:\n", + " registers['pc'] += int(o)\n", + " else:\n", + " registers['pc'] += 1\n" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "instructions = {'hlf': hlf, 'tpl': tpl, 'inc': inc, 'jmp': jmp, 'jie': jie, 'jio': jio}" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "while registers['pc'] < len(program):\n", + " instructions[program[registers['pc']][0]](program[registers['pc']][1])\n", + "registers" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'a': 1, 'b': 307, 'pc': 47}" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "registers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Part 2" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'a': 1, 'b': 160, 'pc': 47}" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "registers = {'a': 1, 'b': 0, 'pc': 0}\n", + "while registers['pc'] < len(program):\n", + " instructions[program[registers['pc']][0]](program[registers['pc']][1])\n", + "registers" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.4.3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/advent23.txt b/advent23.txt new file mode 100644 index 0000000..cc94207 --- /dev/null +++ b/advent23.txt @@ -0,0 +1,47 @@ +jio a, +18 +inc a +tpl a +inc a +tpl a +tpl a +tpl a +inc a +tpl a +inc a +tpl a +inc a +inc a +tpl a +tpl a +tpl a +inc a +jmp +22 +tpl a +inc a +tpl a +inc a +inc a +tpl a +inc a +tpl a +inc a +inc a +tpl a +tpl a +inc a +inc a +tpl a +inc a +inc a +tpl a +inc a +inc a +tpl a +jio a, +8 +inc b +jie a, +4 +tpl a +inc a +jmp +2 +hlf a +jmp -7 \ No newline at end of file -- 2.34.1