Exemplo n.º 1
0
 def paint(self):
     done = False
     x = 0
     y = 1
     while (not done):
         current_coords = Coords(self.current_x, self.current_y)
         current = self.memory.get(current_coords, 1)
         self.program.cin.append(current)
         out, done = self.program.run()
         self.memory[current_coords] = out[0]
         turn = out[1]
         if turn == 0:  #left
             if abs(y) == 1:
                 x = -y
                 y = 0
             else:
                 y = x
                 x = 0
         else:  #right
             if abs(y) == 1:
                 x = y
                 y = 0
             else:
                 y = -x
                 x = 0
         self.current_x += x
         self.current_y += y
Exemplo n.º 2
0
 def test_index(self):
     self.assertEqual([[Coords(2, 1)], [Coords(1, 0)]],
                      index_from_up({
                          -pi: [Coords(2, 2)],
                          -pi / 2: [Coords(1, 1)],
                          0: [Coords(1, 0)],
                          pi / 2: [Coords(2, 1)]
                      }))
Exemplo n.º 3
0
 def __init__(self, program: StatefulIntcode):
     self.memory = {Coords(0, 0): 1}
     self.current_x = 0
     self.current_y = 0
     self.program = program
Exemplo n.º 4
0
            1, 21101, 428, 0, 0, 1106, 0, 440, 21101, 709048034148, 0, 1,
            21102, 439, 1, 0, 1106, 0, 440, 99, 109, 2, 21201, -1, 0, 1, 21101,
            0, 40, 2, 21101, 471, 0, 3, 21102, 461, 1, 0, 1105, 1, 504, 109,
            -2, 2106, 0, 0, 0, 1, 0, 0, 1, 109, 2, 3, 10, 204, -1, 1001, 466,
            467, 482, 4, 0, 1001, 466, 1, 466, 108, 4, 466, 10, 1006, 10, 498,
            1101, 0, 0, 466, 109, -2, 2105, 1, 0, 0, 109, 4, 2101, 0, -1, 503,
            1207, -3, 0, 10, 1006, 10, 521, 21101, 0, 0, -3, 22102, 1, -3, 1,
            21201, -2, 0, 2, 21102, 1, 1, 3, 21102, 540, 1, 0, 1106, 0, 545,
            109, -4, 2105, 1, 0, 109, 5, 1207, -3, 1, 10, 1006, 10, 568, 2207,
            -4, -2, 10, 1006, 10, 568, 22101, 0, -4, -4, 1105, 1, 636, 21201,
            -4, 0, 1, 21201, -3, -1, 2, 21202, -2, 2, 3, 21102, 587, 1, 0,
            1106, 0, 545, 21202, 1, 1, -4, 21102, 1, 1, -1, 2207, -4, -2, 10,
            1006, 10, 606, 21101, 0, 0, -1, 22202, -2, -1, -2, 2107, 0, -3, 10,
            1006, 10, 628, 22101, 0, -1, 1, 21101, 628, 0, 0, 105, 1, 503,
            21202, -2, -1, -2, 22201, -4, -2, -4, 109, -5, 2105, 1, 0
        ], []))
    robot.paint()
    max_x = max(robot.memory.keys(), key=lambda it: it.x).x
    min_x = min(robot.memory.keys(), key=lambda it: it.x).x
    max_y = max(robot.memory.keys(), key=lambda it: it.y).y
    min_y = min(robot.memory.keys(), key=lambda it: it.y).y
    for y in reversed(range(min_y, max_y + 1)):
        for x in range(min_x, max_x + 1):
            color = robot.memory.get(Coords(x, y), 0)
            if color > 0:
                print('#', end='', flush=True)
            else:
                print('.', end='', flush=True)
        print(flush=True)
    exit()
Exemplo n.º 5
0
 def test_to_polar(self):
     self.assertEqual((pi / 2, 1), Coords(0, 1).to_polar())
     self.assertEqual((0, 1), Coords(1, 0).to_polar())
     self.assertEqual((-pi / 2, 1), Coords(0, -1).to_polar())
     self.assertEqual(3 * pi / 4, Coords(-1, 1).to_polar()[0])
     print(Coords(-1, 0).to_polar())
Exemplo n.º 6
0
 def test_group_by_angle(self):
     self.assertEqual({0: [Coords(1, 0), Coords(2, 0)]},
                      group_by_angle(Coords(
                          0, 0), [Coords(2, 0), Coords(1, 0)]))
Exemplo n.º 7
0
 def test_polar_with_ref(self):
     self.assertEqual((0, 1), Coords(2, 1).to_polar(ref=(1, 1)))