Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def jumpleft(Pads,p):
  4.     if (Pads[p]<=p and Pads[p]>0):
  5.         if (Pads[p-Pads[p]]>0):
  6.             Pads[p-Pads[p]]+=Pads[p]
  7.             Pads[p] = 0
  8.             return Pads, 1
  9.     return Pads, 0
  10.  
  11. def jumpright(Pads,p):
  12.     if (Pads[p]<n-p and Pads[p]>0):
  13.         if (Pads[p+Pads[p]]>0):
  14.             Pads[p+Pads[p]]+=Pads[p]
  15.             Pads[p] = 0
  16.             return Pads, 1
  17.     return Pads, 0
  18.    
  19. def randomjump(Pads,p,strin):
  20.     if (np.random.rand()<0.5):
  21.         if (jumpright(Pads,p)[1]==1):
  22.             strin+=str(p)+"r "
  23.     else:
  24.         if (jumpleft(Pads,p)[1]==1):
  25.             strin+=str(p)+"l "
  26.     return strin
  27. def check(Pads):
  28.     l,r = 0,0
  29.     for i in xrange(n):
  30.         if (Pads[i]>0):
  31.             if (Pads[i]<n-i):
  32.                 if (Pads[i+Pads[i]]>0):
  33.                     r=1
  34.             if (Pads[i]<=i):
  35.                 if (Pads[i-Pads[i]]>0):
  36.                     l=1
  37.     if (l==0 and r==0):
  38.         return 0
  39.     else:
  40.         return 1
  41. def checkwin(Pads):
  42.     t=0
  43.     for i in xrange(len(Pads)):
  44.         if (Pads[i]>0):
  45.             t+=1
  46.     if (t==1):
  47.         return 1
  48.     else:
  49.         return 0
  50.  
  51. s=5
  52. d=100000
  53. for t in xrange(10):  
  54.     n=19+t
  55.     print n
  56.     for r in xrange(d):
  57.         st = ""
  58.         Pads = np.ones(n)
  59.         Pads[1]=Pads[n-2]=-1
  60.         while(check(Pads)==1):
  61.             for i in xrange(s):        #checks back if its unsolvable every s (5) Steps
  62.                 st = randomjump(Pads,int(n*np.random.rand()),st)    #tries a randomly chosen jump, iit doesnt do anything if the jump is not possible
  63.         if (r%1000==0):
  64.            print r
  65.         if (checkwin(Pads)==1):            
  66.                 print Pads
  67.               #  print r
  68.                 print st
  69.                 break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement