tintin10

AoC day 3 part 1

Dec 27th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. from math import sqrt
  2. '''
  3. 37-36-35-34-33-32-31
  4. 38-17-16-15-14-13-30
  5. 39-18-5--4--3--12-29
  6. 40-19-6--1--2--11-28
  7. 41-20-7--8--9--10-27
  8. 42-21-22-23-24-25-26
  9. 43-44-45-46-47-48-49-50
  10. '''
  11.  
  12. class runningMan():
  13.     def __init__(self,target):
  14.         self.mode = ">>>"
  15.         self.target = target
  16.         self.coordinate = [0,0]
  17.     def changeMode(self,modeInput):
  18.         if modeInput in (">>>","<<<","^^^","VVV"):
  19.             self.mode = modeInput
  20.     def runForward(self,currentNumber):
  21.         if currentNumber not in (">>>","<<<","^^^","VVV"):
  22.             if self.mode == ">>>":
  23.                 self.coordinate[0] += 1
  24.             elif self.mode == "<<<":
  25.                 self.coordinate[0] -= 1
  26.             elif self.mode == "^^^":
  27.                 self.coordinate[1] += 1
  28.             elif self.mode == "VVV":
  29.                 self.coordinate[1] -= 1
  30.             if currentNumber == 1:  
  31.                 self.coordinate = [0,0]
  32.         else:
  33.             self.changeMode(currentNumber)
  34.         if currentNumber == self.target: # Set up output
  35.             self.total = 0
  36.             for i in self.coordinate:
  37.                 self.total += sqrt(i**2)
  38.             print("The distance is:",self.total)
  39.    
  40. def rightUp(lijstInput):
  41.     global id
  42.     id += 1
  43.     lijstInput.append("<<<") #+str(id)
  44.     return lijstInput
  45.    
  46. def rightDown(lijstInput):
  47.     global id
  48.     id += 1
  49.     lijstInput.append("^^^")
  50.     return lijstInput  
  51.    
  52. def leftUp(lijstInput):
  53.     global id
  54.     id += 1
  55.     lijstInput.append("VVV")
  56.     return lijstInput  
  57.    
  58. def leftDown(lijstInput):
  59.     global id
  60.     id += 1
  61.     lijstInput.append(">>>")
  62.     return lijstInput
  63.  
  64. while True:
  65.     puzzleInput = int(input("puzzleInput:")) # Mine is 347991
  66.     id = 0
  67.     i = 3
  68.     lijst = [1,2,"^^^"]
  69.     start = 1
  70.     normaalCounter = 0
  71.     normaal = 1
  72.     corner = 1
  73.    
  74.     while i < puzzleInput+1:
  75.         lijst.append(i)
  76.         normaalCounter += 1
  77.         if normaal == normaalCounter:
  78.             if corner == 3:
  79.                 normaal += 1
  80.                 normaalCounter = 0
  81.                 lijst = leftDown(lijst)
  82.                 corner = 0
  83.             elif corner == 2:
  84.                 corner += 1
  85.                 normaalCounter = 0
  86.                 lijst = leftUp(lijst)
  87.             elif corner == 1:
  88.                 normaal = normaal + 1
  89.                 normaalCounter = 0
  90.                 corner += 1
  91.                 lijst = rightUp(lijst)
  92.             elif corner == 0:
  93.                 lijst = rightDown(lijst)
  94.                 corner += 1
  95.                 normaalCounter = 0
  96.         i += 1
  97.  
  98.     walker = runningMan(puzzleInput)
  99.     for i in lijst:
  100.         walker.runForward(i)
  101.         if i == puzzleInput:
  102.             break
Advertisement
Add Comment
Please, Sign In to add comment