1
0
Fork 0
This commit is contained in:
Lucidiot 2017-12-07 19:07:58 +01:00
commit bb5f763702
4 changed files with 61 additions and 0 deletions

19
2016/1/route.py Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env python3
import sys, re
instructions = re.findall(r"(R|L)([0-9]+)", sys.stdin.readline().strip())
headings = [(0, 1), (1, 0), (0, -1), (-1, 0)]
h, x, y = 0, 0, 0
visited, part2 = [(x, y)], None
for i in instructions:
if i[0] == 'L':
h = (h - 1) % len(headings)
elif i[0] == 'R':
h = (h + 1) % len(headings)
for _ in range(int(i[1])):
x = x + headings[h][0]
y = y + headings[h][1]
if (x, y) in visited and part2 is None:
part2 = (x, y)
else:
visited.append((x, y))
print(abs(x) + abs(y), abs(part2[0]) + abs(part2[1]))

31
2016/2/code.py Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
import sys
lines = [line.strip() for line in sys.stdin.readlines()]
# keypad = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
keypad = ((None, None, 1, None, None),
(None, 2, 3, 4, None),
(5, 6, 7, 8, 9),
(None, 'A', 'B', 'C', None),
(None, None, 'D', None, None))
x, y, code = 0, 2, ""
for line in lines:
for c in line:
if c == 'D':
if y + 1 >= len(keypad) or keypad[y + 1][x] is None:
continue
y = y + 1
elif c == 'U':
if y - 1 < 0 or keypad[y - 1][x] is None:
continue
y = y - 1
elif c == 'L':
if x - 1 < 0 or keypad[y][x - 1] is None:
continue
x = x - 1
elif c == 'R':
if x + 1 >= len(keypad[y]) or keypad[y][x + 1] is None:
continue
x = x + 1
code = code + str(keypad[y][x])
print(code)

5
2016/3/triangle.py Normal file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env python3
import sys, re
regex = re.compile(r'([0-9]+)')
data = [sorted([int(c) for c in regex.findall(line.strip())]) for line in sys.stdin.readlines()]
print(sum(1 for triangle in data if triangle[0] + triangle[1] > triangle[2]))

6
2016/3/triangle2.py Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env python3
import sys, re
from itertools import zip_longest
regex = re.compile(r'([0-9]+)')
data = [zip_longest(*([iter(col)] * 3)) for col in zip(*[[int(c) for c in regex.findall(line.strip())] for line in sys.stdin.readlines()])]
print(sum(sum(t[0] + t[1] > t[2] for t in [sorted(t) for t in col]) for col in data))