Advertisement
Guest User

Letter cogwheels

a guest
Sep 27th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.39 KB | None | 0 0
  1. #https://puzzling.stackexchange.com/questions/111872/spin-the-letter-cogwheels
  2.  
  3. class Cog:
  4.     def __init__(self,display,current="",size=5):
  5.         self.display = display
  6.         if current=="":
  7.             self.current = display[:size]
  8.         else:
  9.             self.current = current
  10.         self.num_cogs = len(display)
  11.         self.pos = display.index(self.current)
  12.         self.startpos = self.pos
  13.         self.size=size
  14.         self.display = self.display+self.display
  15.  
  16.     def __str__(self):
  17.         return self.display[self.pos:self.pos+self.size]
  18.  
  19.     def __repl__(self):
  20.         return self.display[self.pos:self.pos+self.size]
  21.  
  22.     def show(self):
  23.         return self.display[self.pos:self.pos+self.size]
  24.  
  25.     def bumpleft(self):
  26.         self.pos = (self.pos-1)%self.num_cogs
  27.        
  28.     def bumpright(self):
  29.         self.pos = (self.pos+1)%self.num_cogs
  30.  
  31.     def countbumps(self):
  32.         return min([(+self.startpos-self.pos)%self.num_cogs,
  33.                     (-self.startpos+self.pos)%self.num_cogs])
  34.    
  35.  
  36. def printcogs(cogs):
  37.     print("1"*5+"2"*5+"3"*5+"4"*5+"5"*5)
  38.     for row in cogs:
  39.         temp = ""
  40.         for cog in row:
  41.             temp = temp + str(cog)
  42.         print(temp)
  43.  
  44. cogs = [[],[]]
  45. toprow = ["when dissolving ", "your being so that", " your stock of primetime ", "games is sufficiently", " hardy remember salt"]
  46. botrow = ["we nevertheless ", "want to let you know", "that down around ", "your neck of the woods", " is an unguarded grove"]
  47. topdisp = " dissing sour sames ember"
  48. botdisp = "less want round the grove"
  49. for i,r in enumerate(toprow):
  50.     cogs[0].append(Cog(r,topdisp[i*5:i*5+5]))
  51. for i,r in enumerate(botrow):
  52.     cogs[1].append(Cog(r,botdisp[i*5:i*5+5]))
  53.  
  54. lastmove="11r"
  55. while True:
  56.     printcogs(cogs)
  57.     totbumps = 0
  58.     for row in cogs:
  59.         for cog in row:
  60.             totbumps = totbumps + cog.countbumps()
  61.     print("Bumps so far: {:d}".format(totbumps))
  62.     res = input("Enter ##L/R (q to quit. Enter to repeat previous command) ")
  63.     if res.lower()=="q": break
  64.     if res=="": res = lastmove
  65.     try:
  66.         if len(res)==2:
  67.             cogs[int(res[0])-1][int(res[1])-1].bumpright()
  68.         elif res[2].lower()=="l":
  69.             cogs[int(res[0])-1][int(res[1])-1].bumpleft()
  70.         elif res[2].lower()=="r":
  71.             cogs[int(res[0])-1][int(res[1])-1].bumpright()
  72.         lastmove = res
  73.     except:
  74.         pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement