Beispiel #1
0
        else:
            if not reversion:
                path.append(direction)
            else:
                reversion = False
            x += moves[direction][0]
            y += moves[direction][1]
            o2.add((x, y))
            if (x,y) in counts:
                if len(path)+1 < counts[(x,y)]:
                    counts[(x,y)] = len(path)
            else:
                counts[(x,y)] = len(path)
            i = 0
            while (x + moves[direction][0], y + moves[direction][1]) in valid.union(wall, o2):
                if (x + moves[direction][0], y + moves[direction][1]) in counts:
                    if counts[(x + moves[direction][0], y + moves[direction][1])] > (len(path)+1):
                        counts[(x + moves[direction][0], y + moves[direction][1])] = len(path)+1
                direction = next_dir[direction]
                i += 1
                if i == 4:
                    direction = revert[path.pop()]
                    reversion = True
                    break
        vm.stopped = False
        vm.set_input(direction)
        if (count == 2455):
            break
    print(counts[(16, -12)])

Beispiel #2
0
 y = 0
 facing = 0  # 0 - Up, 1 Right, 2 Down, 3 Left
 while not vm.is_done():
     vm.run()
     colour = vm.output
     area[(x, y)] = colour
     vm.stopped = False
     vm.run()
     direction = int(vm.output)
     if direction:
         facing = (facing + 1) % 4
     else:
         facing = (facing - 1) % 4
     x, y = move(x, y, facing)
     if not vm.is_done():
         vm.set_input(area.get((x, y), "0"))
 print(len(area.keys()))
 lowestx = 0
 maxx = 0
 maxy = 0
 lowesty = 0
 for set in area.keys():
     if set[0] < lowestx:
         lowestx = set[0]
     elif set[0] > maxx:
         maxx = set[0]
     if set[1] < lowesty:
         lowesty = set[1]
     elif set[1] > maxy:
         maxy = set[1]
 output = [['.' for i in range(lowesty, maxy + 1)]