+/AoC

advent of code

git clone https://git.julia.blue/+/AoC

Joseph RyanStart 2018!38c0746

master
891 B36 linesraw
1board = open("input.txt").readlines()
2board.insert(0, ' ' * len(board[0]))
3board.append(' ' * len(board[0]))
4board = [' ' + i + ' ' for i in board]
5
6y = 1
7x = board[1].index('|')
8ydir = 1
9xdir = 0
10steps = 0
11
12print "Part 1: ",
13
14while board[y][x] != ' ':
15    #print "pos:", x, y, "\t", board[y][x], "\tdir:", xdir, ydir
16    steps += 1
17    current = board[y][x]
18    if current.isalpha():
19        print '\b' + current,
20    if not current in '|-':
21        temp = '|'
22        if xdir == 0:
23            temp = '-'
24            for tempdir in range(-1, 2, 2):
25                if board[y][x + tempdir] == temp:
26                    ydir = 0
27                    xdir = tempdir
28        else:
29            for tempdir in range(-1, 2, 2):
30                if board[y + tempdir][x] == temp:
31                    xdir = 0
32                    ydir = tempdir
33    x += xdir
34    y += ydir
35
36print "\nPart 2:", steps