Solve 2016 days 2 and 3.
This commit is contained in:
34
2016/d2.py
Normal file
34
2016/d2.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
from lib import *
|
||||||
|
|
||||||
|
second = True
|
||||||
|
|
||||||
|
if second is False:
|
||||||
|
keypad = "123\n456\n789".splitlines()
|
||||||
|
else:
|
||||||
|
keypad = "00100\n02340\n56789\n0ABC0\n00D00".splitlines()
|
||||||
|
|
||||||
|
data = open(0).read()
|
||||||
|
|
||||||
|
DIRS = {
|
||||||
|
"D": (1, 0),
|
||||||
|
"L": (0, -1),
|
||||||
|
"R": (0, 1),
|
||||||
|
"U": (-1, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
BOUND = len(keypad) - 1
|
||||||
|
pos = (2, 0)
|
||||||
|
r = ""
|
||||||
|
for row in data.splitlines():
|
||||||
|
for c in row:
|
||||||
|
dir = DIRS[c]
|
||||||
|
npos = pos[0] + dir[0], pos[1] + dir[1]
|
||||||
|
if npos[0] >= 0 and npos[0] <= BOUND and npos[1] >= 0 and npos[1] <= BOUND:
|
||||||
|
if keypad[npos[0]][npos[1]] != "0":
|
||||||
|
pos = npos
|
||||||
|
r += keypad[pos[0]][pos[1]]
|
||||||
|
|
||||||
|
print(r)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
21
2016/d3.py
Normal file
21
2016/d3.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from lib import *
|
||||||
|
|
||||||
|
second = True
|
||||||
|
data = open(0).read()
|
||||||
|
|
||||||
|
res = 0
|
||||||
|
if not second:
|
||||||
|
for row in data.splitlines():
|
||||||
|
a, b, c = list(map(int, row.split()))
|
||||||
|
if a + b > c and a + c > b and b + c > a:
|
||||||
|
res += 1
|
||||||
|
else:
|
||||||
|
rows = list(map(lambda row: row.split(), data.splitlines()))
|
||||||
|
for coli in range(len(rows[0])):
|
||||||
|
for rowi in range(0, len(rows), 3):
|
||||||
|
a = int(rows[rowi][coli])
|
||||||
|
b = int(rows[rowi + 1][coli])
|
||||||
|
c = int(rows[rowi + 2][coli])
|
||||||
|
if a + b > c and a + c > b and b + c > a:
|
||||||
|
res += 1
|
||||||
|
print(res)
|
||||||
@@ -28,7 +28,12 @@ written in Python.
|
|||||||
- Day 21: 25:52 cute bug where I didn't consider that no armor is an option
|
- Day 21: 25:52 cute bug where I didn't consider that no armor is an option
|
||||||
- Day 22: That was bad. Did not know how to choose between dfs/bfs and logic errors.
|
- Day 22: That was bad. Did not know how to choose between dfs/bfs and logic errors.
|
||||||
- Day 23:
|
- Day 23:
|
||||||
|
- Day 24:
|
||||||
|
- Day 25:
|
||||||
|
|
||||||
# 2016
|
# 2016
|
||||||
|
|
||||||
- Day 1: 29:00 That was emberassingly slow. Out of my rhythm?
|
- Day 1: 29:00 That was emberassingly slow. Out of my rhythm?
|
||||||
|
- Day 2: 13:24 Getting back into it but still slow af, obviously.
|
||||||
|
- Day 3: 11:20 Ugly and slow.
|
||||||
|
- Day 4:
|
||||||
|
|||||||
Reference in New Issue
Block a user