示例#1
0
def main():
    global comp, network
    prog = intCodeClass.Program(args.code)
    # Prep network messages
    for i in range(50):
        network[i] = i
    print(network)
示例#2
0
文件: oxybot.py 项目: resb53/advent
def main():
    global win, pos, start, expl, curses
    # Read ch from stdin
    fh = sys.stdin.fileno()
    old = termios.tcgetattr(fh)
    tty.setraw(sys.stdin.fileno())
    # Prepare screen
    win = curses.initscr()
    win.clear()
    win.refresh()
    curses.noecho()
    curses.cbreak()
    curses.curs_set(0)
    # Handle SIGINT gracefully
    signal.signal(signal.SIGINT, sigintClean)
    # Get starting point
    winy, winx = win.getmaxyx()
    # Start in the middle
    pos = [winx // 2, winy // 2]
    expl = [winx // 2, winy // 2]  # explore this
    start = [winx // 2, winy // 2]
    if pos[1] not in grid:
        grid[pos[1]] = {}
    grid[pos[1]][pos[0]] = 1
    # Draw grid
    drawin()
    # Prepare intcode computer
    prog = intCodeClass.Program('inputs/oxygen.txt')
    prog.run(i=instr_in, o=instr_out)
    # Cleanup
    termios.tcsetattr(fh, termios.TCSADRAIN, old)
    curses.endwin()
示例#3
0
def main():
    global grid, io

    # part 1
    #count = 0
    #for y in range(50):
    #    grid[y] = {}
    #    for x in range(50):
    #        io['inp'] = [x, y]
    #        prog = intCodeClass.Program(args.code)
    #        prog.run(i=instr_in, o=instr_out)
    #        grid[y][x] = io['out'].pop(0)
    #        count += grid[y][x]

    #drawGrid(grid)
    #print(count)

    # part 2
    debug = {}  # {y: [[start, end], [genstart, genend]]

    # No pattern but have estimate range
    initial = [{'y': 3, 'start': 2, 'end': 2}]
    cache = deque(initial, maxlen=99)
    for y in range(4, 1100):  # Start at row 2 to avoid blank lines
        beam = 0
        x = cache[-1][
            'start'] - 2  #Start at where the last rows first # was seen
        start = 0
        end = 0
        print('y:' + str(y))
        while beam != 2:
            x += 1
            print(str(x) + ':', end='')
            io['inp'] = [x, y]
            prog = intCodeClass.Program(args.code)
            prog.run(i=instr_in, o=instr_out)
            test = io['out'].pop(0)
            print(str(test) + '; ', end='')
            if beam == 0 and test == 1:
                beam += 1
                start = x
                # Skip forwards towards last # could be 1 less than last width
                if y > 20:
                    x += (cache[-1]['end'] - cache[-1]['start'] - 2)
            elif beam == 1 and test == 0:
                beam += 1
                end = x - 1
                new = {'y': y, 'start': start, 'end': end}
                print('\n' + str(new))
                # Cache 100 rows ago, and see if old end - new start = 99
                if cache[0]['end'] - start >= 99:
                    print('Old: ' + str(cache[0]))
                    print('New: ' + str(new))
                    print('Answer: ' +
                          str((cache[0]['end'] - 99) * 10000 + cache[0]['y']))
                    sys.exit(0)
                else:
                    cache.append(new)
示例#4
0
文件: ascii.py 项目: resb53/advent
def main():
    # Prepare intcode computer
    prog = intCodeClass.Program('inputs/ascii.txt')
    # Do part 1: Find intersections and calculate alignment parameters
    #prog.run(o=instr_out)
    #cleanGrid()
    #printGrid()
    #intersect()
    # Do part 2:
    prog.mem[0] = 2
    prog.run(i=instr_in)
示例#5
0
def main():
    global grid, game
    # Prepare screen
    win = curses.initscr()
    win.clear()
    win.refresh()
    game = curses.newwin(25, 43, 5, 10)
    curses.noecho()
    curses.cbreak()
    curses.curs_set(0)
    # Prepare intcode computer
    prog = intCodeClass.Program('inputs/arcade.txt')
    # insert coin
    prog.mem[0] = 2
    prog.run(i=instr_in,o=instr_out)
    # Hold then reset screen
    game.addstr(23, 10, "You win! Your score:")
    game.refresh()
    time.sleep(3)
    curses.endwin()
示例#6
0
文件: jumping.py 项目: resb53/advent
def main():
    prog = intCodeClass.Program(args.code)
    prog.run(i=instr_in, o=instr_out)
示例#7
0
def main():
    prog = intCodeClass.Program('inputs/arcade.txt')
    prog.run()