X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=07-interpreter%2Fmachine-code.ipynb;h=2bb22230c55db64aa3cb6e4069836942bb8a00ee;hb=093a2a306b3b0d536060e0bca23167d0c99dcd5a;hp=69cd43ff07b09f91c79e0082aa7cd6c0aa40b2a1;hpb=e405461a789315af95c5ae0e90d63d9fd7d81d37;p=ou-summer-of-code-2017.git diff --git a/07-interpreter/machine-code.ipynb b/07-interpreter/machine-code.ipynb index 69cd43f..2bb2223 100644 --- a/07-interpreter/machine-code.ipynb +++ b/07-interpreter/machine-code.ipynb @@ -416,17 +416,17 @@ { "data": { "text/plain": [ - "{'a': 0,\n", - " 1: 10,\n", - " 'pc': 6,\n", - " 'c': 20,\n", + "{1: 10,\n", + " 'a': 0,\n", + " 'b': 10,\n", " 'instructions': [(, ['a', 10]),\n", " (, ['a']),\n", " (, ['b']),\n", " (, ['b', 1]),\n", " (, ['a', 2]),\n", " (, [-4])],\n", - " 'b': 10}" + " 'c': 20,\n", + " 'pc': 6}" ] }, "execution_count": 22, @@ -457,17 +457,17 @@ { "data": { "text/plain": [ - "{'a': 0,\n", - " 1: 10,\n", - " 'pc': 6,\n", - " 'c': 20,\n", + "{1: 10,\n", + " 'a': 0,\n", + " 'b': 10,\n", " 'instructions': [(, ['a', 10]),\n", " (, ['a']),\n", " (, ['b']),\n", " (, ['b', 1]),\n", " (, ['a', 2]),\n", " (, [-4])],\n", - " 'b': 10}" + " 'c': 20,\n", + " 'pc': 6}" ] }, "execution_count": 23, @@ -658,7 +658,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -667,7 +667,7 @@ "'1: 0, a: 0, b: 0, c: 27, pc: 11'" ] }, - "execution_count": 39, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -696,7 +696,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -725,7 +725,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -734,7 +734,7 @@ "'1: 0, a: 0, b: 0, c: 10, pc: 13'" ] }, - "execution_count": 29, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } @@ -765,7 +765,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -798,7 +798,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -807,7 +807,7 @@ "'1: 0, a: 52, b: 0, c: 0, pc: 48'" ] }, - "execution_count": 31, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -889,7 +889,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -898,7 +898,7 @@ "40" ] }, - "execution_count": 32, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -909,7 +909,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 34, "metadata": { "collapsed": true }, @@ -930,7 +930,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -939,7 +939,7 @@ "52" ] }, - "execution_count": 34, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -950,7 +950,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -959,7 +959,7 @@ "(250504, 937)" ] }, - "execution_count": 35, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -970,7 +970,27 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(52, 9)" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max([(max_collatz(i), i) for i in range(1, 10)])" + ] + }, + { + "cell_type": "code", + "execution_count": 37, "metadata": { "scrolled": true }, @@ -1079,7 +1099,7 @@ " (99, 0, 448)]" ] }, - "execution_count": 36, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -1116,7 +1136,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 loop, best of 3: 38.6 s per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "show_machine(execute(program, initial_state={'a': 937}))" + ] + }, + { + "cell_type": "code", + "execution_count": 39, "metadata": { "collapsed": true },