Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def jumpleft(Pads,p):
- if (Pads[p]<=p and Pads[p]>0):
- if (Pads[p-Pads[p]]>0):
- Pads[p-Pads[p]]+=Pads[p]
- Pads[p] = 0
- return Pads, 1
- return Pads, 0
- def jumpright(Pads,p):
- if (Pads[p]<n-p and Pads[p]>0):
- if (Pads[p+Pads[p]]>0):
- Pads[p+Pads[p]]+=Pads[p]
- Pads[p] = 0
- return Pads, 1
- return Pads, 0
- def randomjump(Pads,p,strin):
- if (np.random.rand()<0.5):
- if (jumpright(Pads,p)[1]==1):
- strin+=str(p)+"r "
- else:
- if (jumpleft(Pads,p)[1]==1):
- strin+=str(p)+"l "
- return strin
- def check(Pads):
- l,r = 0,0
- for i in xrange(n):
- if (Pads[i]>0):
- if (Pads[i]<n-i):
- if (Pads[i+Pads[i]]>0):
- r=1
- if (Pads[i]<=i):
- if (Pads[i-Pads[i]]>0):
- l=1
- if (l==0 and r==0):
- return 0
- else:
- return 1
- def checkwin(Pads):
- t=0
- for i in xrange(len(Pads)):
- if (Pads[i]>0):
- t+=1
- if (t==1):
- return 1
- else:
- return 0
- s=5
- d=100000
- for t in xrange(10):
- n=19+t
- print n
- for r in xrange(d):
- st = ""
- Pads = np.ones(n)
- Pads[1]=Pads[n-2]=-1
- while(check(Pads)==1):
- for i in xrange(s): #checks back if its unsolvable every s (5) Steps
- st = randomjump(Pads,int(n*np.random.rand()),st) #tries a randomly chosen jump, iit doesnt do anything if the jump is not possible
- if (r%1000==0):
- print r
- if (checkwin(Pads)==1):
- print Pads
- # print r
- print st
- break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement