adventofcode

https://adventofcode.com/
Log | Files | Refs

puzzle11.py (1108B)


      1 x, y = [0.0], [0.0]
      2 
      3 def find_least_steps(direction):
      4     step(direction)
      5     cur_x, cur_y = x[0], y[0]
      6     steps = 0
      7 
      8     while x[0] != 0:
      9         if x[0] < 0:
     10             if y[0] < 0:
     11                 step("ne")
     12             else:
     13                 step("se")
     14         else:
     15             if y[0] < 0:
     16                 step("nw")
     17             else:
     18                 step("sw")
     19         steps += 1
     20     while y[0] != 0:
     21         if y[0] < 0:
     22             step("n")
     23         else:
     24             step("s")
     25         steps += 1
     26 
     27     x[0], y[0] = cur_x, cur_y
     28     return steps
     29 
     30 def step(direction):
     31     if direction == "n":
     32         y[0] += 1
     33     if direction == "s":
     34         y[0] -= 1
     35     if direction == "nw":
     36         x[0] -= 1
     37         y[0] += 0.5
     38     if direction == "ne":
     39         x[0] += 1
     40         y[0] += 0.5
     41     if direction == "sw":
     42         x[0] -= 1
     43         y[0] -= 0.5
     44     if direction == "se":
     45         x[0] += 1
     46         y[0] -= 0.5
     47 
     48 with open('files/puzzle11.txt') as f:
     49     furthest_steps = max([find_least_steps(direction) for direction in f.read().strip().split(',')])
     50 
     51 print find_least_steps("")
     52 print furthest_steps