Update readme and lib and start 2015.
This commit is contained in:
22
2015/d1.py
Normal file
22
2015/d1.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from lib import *
|
||||
|
||||
data = open(0).read()
|
||||
|
||||
part_2 = True
|
||||
|
||||
floor = 0
|
||||
for i, c in enumerate(data):
|
||||
if c == "(":
|
||||
floor += 1
|
||||
elif c == ")":
|
||||
floor -= 1
|
||||
else:
|
||||
print(c)
|
||||
assert False
|
||||
|
||||
if part_2 and floor == -1:
|
||||
print(i + 1)
|
||||
break
|
||||
|
||||
if not part_2:
|
||||
print(floor)
|
||||
19
2015/d2.py
Normal file
19
2015/d2.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from lib import *
|
||||
|
||||
data = open(0).readlines()
|
||||
|
||||
part_1 = True
|
||||
if part_1:
|
||||
a = 0
|
||||
for line in data:
|
||||
l, w, h = list(map(int, line.split("x")))
|
||||
slack = min([l * w, w * h, h * l])
|
||||
a += (2*l*w + 2*w*h + 2*h*l + slack)
|
||||
else:
|
||||
a = 0
|
||||
for line in data:
|
||||
l, w, h = list(map(int, line.split("x")))
|
||||
sd = min([2 * (l + w), 2 * (w + h), 2 * (h + l)])
|
||||
a += sd + (l * w * h)
|
||||
|
||||
print(a)
|
||||
41
2015/d3.py
Normal file
41
2015/d3.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import sys
|
||||
from lib import *
|
||||
|
||||
data = open(0).read()
|
||||
|
||||
part_1 = False
|
||||
|
||||
DIRS = {
|
||||
"^": (-1, 0),
|
||||
">": (0, 1),
|
||||
"v": (1, 0),
|
||||
"<": (0, -1),
|
||||
}
|
||||
|
||||
if part_1:
|
||||
pos = (0, 0)
|
||||
poss = set([pos])
|
||||
|
||||
for c in data:
|
||||
d = DIRS[c]
|
||||
pos = pos[0] + d[0], pos[1] + d[1]
|
||||
poss.add(pos)
|
||||
|
||||
print(len(poss))
|
||||
sys.exit(0)
|
||||
|
||||
a = (0, 0)
|
||||
b = (0, 0)
|
||||
poss = set([a, b])
|
||||
for i, c in enumerate(data):
|
||||
if i % 2 == 0:
|
||||
d = DIRS[c]
|
||||
a = a[0] + d[0], a[1] + d[1]
|
||||
poss.add(a)
|
||||
else:
|
||||
d = DIRS[c]
|
||||
b = b[0] + d[0], b[1] + d[1]
|
||||
poss.add(b)
|
||||
|
||||
print(len(poss))
|
||||
sys.exit(0)
|
||||
22
2015/d4.py
Normal file
22
2015/d4.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from lib import *
|
||||
import hashlib
|
||||
|
||||
part_1 = True
|
||||
|
||||
if part_1:
|
||||
digits = 5
|
||||
else:
|
||||
digits = 6
|
||||
|
||||
data = open(0).read().strip()
|
||||
|
||||
for i in range(10**9):
|
||||
text = data + str(i)
|
||||
md5_hash = hashlib.md5(text.encode()).hexdigest()
|
||||
for c in md5_hash[:digits]:
|
||||
if c != "0":
|
||||
break
|
||||
else:
|
||||
print(i)
|
||||
break
|
||||
|
||||
53
2015/d5.py
Normal file
53
2015/d5.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from lib import *
|
||||
|
||||
data = open(0).read()
|
||||
|
||||
part_1 = True
|
||||
if part_1:
|
||||
res = 0
|
||||
for line in data.splitlines():
|
||||
vc = 0
|
||||
for c in line:
|
||||
if c in "aoeui":
|
||||
vc += 1
|
||||
if vc < 3:
|
||||
continue
|
||||
|
||||
prev = None
|
||||
for c in line:
|
||||
if c == prev:
|
||||
break
|
||||
prev = c
|
||||
else:
|
||||
continue
|
||||
|
||||
contains = False
|
||||
ss = ["ab", "cd", "pq", "xy"]
|
||||
for s in ss:
|
||||
if s in line:
|
||||
contains = True
|
||||
|
||||
if contains:
|
||||
continue
|
||||
res += 1
|
||||
print(res)
|
||||
else:
|
||||
res = 0
|
||||
for line in data.splitlines():
|
||||
pairs = {}
|
||||
for i in range(0, len(line) - 1):
|
||||
p = line[i:i+2]
|
||||
if p in pairs and i > pairs[p] + 1:
|
||||
break
|
||||
if not p in pairs:
|
||||
pairs[p] = i
|
||||
else:
|
||||
continue
|
||||
|
||||
for i in range(0, len(line) - 2):
|
||||
if line[i] == line[i + 2]:
|
||||
break
|
||||
else:
|
||||
continue
|
||||
res += 1
|
||||
print(res)
|
||||
1
2015/lib.py
Symbolic link
1
2015/lib.py
Symbolic link
@@ -0,0 +1 @@
|
||||
../lib.py
|
||||
Reference in New Issue
Block a user