%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from random import shufflem=0
for k in range(10000):
theone = saw(1000)
# print(len(theone), end=' ')
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
print(m)
base = [[1,0], [0,1], [-1,0], [0,-1]]
w = [[0,0]]
def walk():
L = base.copy()
shuffle(L)
work = True
while work:
d = L.pop()
new_step = [w[-1][0] + d[0], w[-1][1] + d[1]]
if new_step not in w:
w.append(new_step)
work = False
for i in range(1000):
walk()
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-115-b37382509dc6> in <module> 1 for i in range(1000): ----> 2 walk() <ipython-input-114-bd7a02e595a7> in walk() 4 work = True 5 while work: ----> 6 d = L.pop() 7 new_step = [w[-1][0] + d[0], w[-1][1] + d[1]] 8 if new_step not in w: IndexError: pop from empty list
i
62
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda60cdd0b8>]
d
[-1, 0]
new_step = [w[-1][0] + d[0], w[-1][1] + d[1]]
[0,0] in w
True
w
[array([0, 0])]
def new_walk(n):
base = [[1,0], [0,1], [-1,0], [0,-1]]
w = [[0,0]]
for i in range(n):
walk()
i
62
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda8188f9b0>]
new_walk(n=1000)
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-130-952131384633> in <module> ----> 1 new_walk(n=1000) <ipython-input-122-98c4101545dc> in new_walk(n) 3 w = [[0,0]] 4 for i in range(n): ----> 5 walk() 6 <ipython-input-114-bd7a02e595a7> in walk() 4 work = True 5 while work: ----> 6 d = L.pop() 7 new_step = [w[-1][0] + d[0], w[-1][1] + d[1]] 8 if new_step not in w: IndexError: pop from empty list
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda70694390>]
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda20344128>]
L = base.copy()
shuffle(L)
L
[[0, 1], [0, -1], [1, 0], [-1, 0]]
L = base.copy()
shuffle(L)
L
[[1, 0], [0, 1], [-1, 0], [0, -1]]
def saw(n=1000):
base = [[1,0], [0,1], [-1,0], [0,-1]]
w = [[0,0]]
L = []
for i in range(n):
L_new = base.copy()
shuffle(L_new)
L.append(L_new)
for i in range(n):
thewalk = L[i]
work = True
do_break = False
while work:
d = thewalk.pop()
new_step = [w[-1][0] + d[0], w[-1][1] + d[1]]
if new_step not in w:
w.append(new_step)
work = False
if thewalk == []:
work = False
do_break = True
if do_break:
break
return w
w = saw(100)
[[0, 0], [-1, 0], [-1, -1], [-1, -2], [0, -2], [0, -1], [1, -1], [1, 0], [2, 0], [2, 1], [1, 1], [0, 1], [0, 2], [1, 2], [1, 3], [1, 4], [0, 4], [0, 5], [-1, 5], [-1, 6], [-2, 6], [-2, 7], [-1, 7], [0, 7], [1, 7], [1, 6], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [1, 10], [1, 11], [1, 12], [0, 12], [0, 11], [0, 10], [-1, 10], [-2, 10], [-3, 10], [-4, 10], [-5, 10], [-5, 11], [-6, 11], [-7, 11], [-7, 10], [-6, 10], [-6, 9], [-5, 9], [-5, 8], [-4, 8], [-4, 9], [-3, 9], [-2, 9], [-1, 9], [0, 9], [0, 8], [-1, 8], [-2, 8], [-3, 8], [-3, 7], [-3, 6], [-4, 6], [-5, 6], [-6, 6], [-7, 6], [-8, 6], [-9, 6], [-9, 5], [-9, 4], [-9, 3], [-10, 3], [-10, 2], [-11, 2], [-11, 1], [-11, 0], [-12, 0], [-12, -1], [-12, -2], [-12, -3], [-13, -3], [-14, -3], [-14, -2], [-15, -2], [-16, -2], [-17, -2], [-18, -2], [-18, -1], [-17, -1], [-16, -1], [-15, -1], [-15, 0], [-15, 1], [-15, 2], [-15, 3], [-15, 4], [-15, 5], [-15, 6], [-16, 6], [-16, 7], [-17, 7]]
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda506abda0>]
w = saw(100)
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda707415c0>]
w = saw(100)
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda403c1588>]
w = saw(100)
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda70784e10>]
w = saw(1000)
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda60f9d710>]
w = saw(1000)
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda81bbb240>]
w = saw(1000)
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda612e2278>]
w = saw(1000)
walk_arr = np.array(w)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda81cb70f0>]
for k in range(1000):
m = 0
theone = saw(1000)
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda61248cc0>]
m=0
for k in range(10000):
theone = saw(1000)
# print(len(theone), end=' ')
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda407a7c88>]
m=0
for k in range(10000):
theone = saw(1000)
# print(len(theone), end=' ')
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
[<matplotlib.lines.Line2D at 0x7fda613b4c18>]
m=0
for k in range(10000):
theone = saw(1000)
# print(len(theone), end=' ')
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
print(m)
335
m=0
for k in range(10000):
theone = saw(1000)
# print(len(theone), end=' ')
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
print(m)
319
m=0
for k in range(10000):
theone = saw(1000)
# print(len(theone), end=' ')
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
print(m)
318
m=0
for k in range(10000):
theone = saw(1000)
# print(len(theone), end=' ')
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
print(m)
324
m=0
for k in range(10000):
theone = saw(1000)
# print(len(theone), end=' ')
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
print(m)
389
m=0
for k in range(10000):
theone = saw(1000)
# print(len(theone), end=' ')
if m < len(theone):
w_max = theone
m = len(theone)
walk_arr = np.array(w_max)
plt.plot(walk_arr[:,0], walk_arr[:,1])
print(m)
310