Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #https://puzzling.stackexchange.com/questions/111872/spin-the-letter-cogwheels
- class Cog:
- def __init__(self,display,current="",size=5):
- self.display = display
- if current=="":
- self.current = display[:size]
- else:
- self.current = current
- self.num_cogs = len(display)
- self.pos = display.index(self.current)
- self.startpos = self.pos
- self.size=size
- self.display = self.display+self.display
- def __str__(self):
- return self.display[self.pos:self.pos+self.size]
- def __repl__(self):
- return self.display[self.pos:self.pos+self.size]
- def show(self):
- return self.display[self.pos:self.pos+self.size]
- def bumpleft(self):
- self.pos = (self.pos-1)%self.num_cogs
- def bumpright(self):
- self.pos = (self.pos+1)%self.num_cogs
- def countbumps(self):
- return min([(+self.startpos-self.pos)%self.num_cogs,
- (-self.startpos+self.pos)%self.num_cogs])
- def printcogs(cogs):
- print("1"*5+"2"*5+"3"*5+"4"*5+"5"*5)
- for row in cogs:
- temp = ""
- for cog in row:
- temp = temp + str(cog)
- print(temp)
- cogs = [[],[]]
- toprow = ["when dissolving ", "your being so that", " your stock of primetime ", "games is sufficiently", " hardy remember salt"]
- botrow = ["we nevertheless ", "want to let you know", "that down around ", "your neck of the woods", " is an unguarded grove"]
- topdisp = " dissing sour sames ember"
- botdisp = "less want round the grove"
- for i,r in enumerate(toprow):
- cogs[0].append(Cog(r,topdisp[i*5:i*5+5]))
- for i,r in enumerate(botrow):
- cogs[1].append(Cog(r,botdisp[i*5:i*5+5]))
- lastmove="11r"
- while True:
- printcogs(cogs)
- totbumps = 0
- for row in cogs:
- for cog in row:
- totbumps = totbumps + cog.countbumps()
- print("Bumps so far: {:d}".format(totbumps))
- res = input("Enter ##L/R (q to quit. Enter to repeat previous command) ")
- if res.lower()=="q": break
- if res=="": res = lastmove
- try:
- if len(res)==2:
- cogs[int(res[0])-1][int(res[1])-1].bumpright()
- elif res[2].lower()=="l":
- cogs[int(res[0])-1][int(res[1])-1].bumpleft()
- elif res[2].lower()=="r":
- cogs[int(res[0])-1][int(res[1])-1].bumpright()
- lastmove = res
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement