Merge pull request #27 from maxalbert/advent-day5-speedup
Advent 2017, day 5: speed up `run` function by avoiding repeated lookup
This commit is contained in:
commit
f594f375de
@ -857,8 +857,9 @@
|
||||
"source": [
|
||||
"def run(program):\n",
|
||||
" memory = list(program)\n",
|
||||
" mlen = len(memory)\n",
|
||||
" pc = steps = 0\n",
|
||||
" while pc in range(len(memory)):\n",
|
||||
" while 0 <= pc < mlen:\n",
|
||||
" steps += 1\n",
|
||||
" oldpc = pc\n",
|
||||
" pc += memory[pc]\n",
|
||||
@ -912,8 +913,9 @@
|
||||
"source": [
|
||||
"def run2(program, verbose=False):\n",
|
||||
" memory = list(program)\n",
|
||||
" mlen = len(memory)\n",
|
||||
" pc = steps = 0\n",
|
||||
" while pc in range(len(memory)):\n",
|
||||
" while 0 <= pc < mlen:\n",
|
||||
" steps += 1\n",
|
||||
" oldpc = pc\n",
|
||||
" pc += memory[pc]\n",
|
||||
|
Loading…
Reference in New Issue
Block a user