diff options
author | Brian Chu <brianmchu42@gmail.com> | 2022-02-21 00:11:06 -0800 |
---|---|---|
committer | Brian Chu <brianmchu42@gmail.com> | 2022-02-21 00:11:06 -0800 |
commit | 0a4fe70d367f0bf1a78602af600052f58a377c34 (patch) | |
tree | 69c2bcd2b54b48968fd52728aaf0e21ca154784c /day19.py | |
parent | 1e2642d8793e6a4fb6cba16cd651d5fdca3e4581 (diff) | |
download | AdventOfCode2017-0a4fe70d367f0bf1a78602af600052f58a377c34.tar.gz |
solutions to day 25 main
Diffstat (limited to 'day19.py')
-rw-r--r-- | day19.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/day19.py b/day19.py new file mode 100644 index 0000000..eddbe77 --- /dev/null +++ b/day19.py @@ -0,0 +1,37 @@ +with open("day19.txt") as diagram: + l = [line.strip('\n') for line in diagram] + +lx, ly = 0, 0 +sx, sy = 0, 0 +while l[sx][sy] == ' ': + sy += 1 +dx, dy = 1, 0 + +ddx = [1, -1, 0, 0] +ddy = [0, 0, -1, 1] +ans = 0 +ret = "" +while True: + ans += 1 + if l[sx][sy].isupper(): + ret += l[sx][sy] + nx, ny = sx + dx, sy + dy + if nx >= 0 and nx < len(l) and ny >= 0 and ny < len(l[nx]) and l[nx][ny] != ' ': + lx, ly, sx, sy = sx, sy, nx, ny + else: + k = 0 + good = False + while k < len(ddx): + dx, dy = ddx[k], ddy[k] + nx, ny = sx + dx, sy + dy + if nx == lx and ny == ly: + k += 1 + continue + if nx >= 0 and nx < len(l) and ny >= 0 and ny < len(l[nx]) and l[nx][ny] != ' ': + lx, ly, sx, sy = sx, sy, nx, ny + good = True + break + k += 1 + if not good: + print("trail ends at {} {} with string {} and length {}".format(sx, sy, ret, ans)) + break \ No newline at end of file |