Compare commits
2 Commits
631205086d
...
9a30c8b88d
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a30c8b88d | |||
| 305fe0b325 |
@@ -1,17 +1,18 @@
|
|||||||
from lib import get_data, Grid2D
|
from lib import get_data
|
||||||
|
|
||||||
required = [
|
required = [
|
||||||
"byr",
|
"byr",
|
||||||
"iyr",
|
"iyr",
|
||||||
"eyr",
|
"eyr",
|
||||||
"hgt",
|
"hgt",
|
||||||
"hcl",
|
"hcl",
|
||||||
"ecl",
|
"ecl",
|
||||||
"pid",]
|
"pid",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# hgt (Height) - a number followed by either cm or in:
|
# hgt (Height) - a number followed by either cm or in:
|
||||||
#
|
#
|
||||||
# If cm, the number must be at least 150 and at most 193.
|
# If cm, the number must be at least 150 and at most 193.
|
||||||
# If in, the number must be at least 59 and at most 76.
|
# If in, the number must be at least 59 and at most 76.
|
||||||
|
|
||||||
|
|||||||
40
2020/d5.py
Normal file
40
2020/d5.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from lib import get_data
|
||||||
|
|
||||||
|
|
||||||
|
def part_1(data):
|
||||||
|
rs = []
|
||||||
|
for line in data.splitlines():
|
||||||
|
rl, ru = 0, 127
|
||||||
|
cl, cu = 0, 7
|
||||||
|
for c in line.strip():
|
||||||
|
rh = (ru - rl) // 2
|
||||||
|
ch = (cu - cl) // 2
|
||||||
|
if c == "B":
|
||||||
|
rl = rl + rh + 1
|
||||||
|
elif c == "F":
|
||||||
|
ru = rl + rh
|
||||||
|
elif c == "R":
|
||||||
|
cl = cl + ch + 1
|
||||||
|
elif c == "L":
|
||||||
|
cu = cl + ch
|
||||||
|
else:
|
||||||
|
assert False
|
||||||
|
assert rl == ru
|
||||||
|
assert cl == cu
|
||||||
|
r_new = rl * 8 + cl
|
||||||
|
rs.append(r_new)
|
||||||
|
|
||||||
|
print(max(rs))
|
||||||
|
rs = sorted(rs)
|
||||||
|
for i in range(len(rs) - 1):
|
||||||
|
if rs[i] + 1 != rs[i + 1]:
|
||||||
|
print(rs[i] + 1)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
data = get_data(__file__)
|
||||||
|
part_1(data)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
24
2020/d6.py
Normal file
24
2020/d6.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from lib import get_data
|
||||||
|
|
||||||
|
|
||||||
|
def part_1(data):
|
||||||
|
r1, r2 = 0, 0
|
||||||
|
for group in data.split("\n\n"):
|
||||||
|
r1 += len(set(group.replace("\n", "")))
|
||||||
|
|
||||||
|
s = set(group.splitlines()[0])
|
||||||
|
for line in group.splitlines():
|
||||||
|
s &= set(line)
|
||||||
|
r2 += len(s)
|
||||||
|
|
||||||
|
print(r1)
|
||||||
|
print(r2)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
data = get_data(__file__)
|
||||||
|
part_1(data)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
47
2020/d7.py
Normal file
47
2020/d7.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
from lib import get_data
|
||||||
|
|
||||||
|
|
||||||
|
def part_1(data):
|
||||||
|
bags = {}
|
||||||
|
for line in data.splitlines():
|
||||||
|
left, right = line.split(" contain ")
|
||||||
|
lb = " ".join(left.split()[:2])
|
||||||
|
rbs = right.replace(" bag", "").replace(" bags", "").replace(".", "").split(",")
|
||||||
|
if "no others" in rbs:
|
||||||
|
rbs = []
|
||||||
|
else:
|
||||||
|
rbs = [[int(v.split()[0]), " ".join(v.split()[1:])] for v in rbs]
|
||||||
|
assert lb not in bags
|
||||||
|
bags[lb] = rbs
|
||||||
|
|
||||||
|
for lb, rbs in bags.items():
|
||||||
|
for t in rbs:
|
||||||
|
if t[0] > 1:
|
||||||
|
t[1] = t[1][:-1]
|
||||||
|
|
||||||
|
can_hold = set(["shiny gold"])
|
||||||
|
can_hold_count = -1
|
||||||
|
while can_hold_count != len(can_hold):
|
||||||
|
can_hold_count = len(can_hold)
|
||||||
|
for lb, rbs in bags.items():
|
||||||
|
for _, bag_color in rbs:
|
||||||
|
if bag_color in can_hold:
|
||||||
|
can_hold.add(lb)
|
||||||
|
print(len(can_hold) - 1)
|
||||||
|
|
||||||
|
def count(color):
|
||||||
|
r = 1 # the bag itself
|
||||||
|
for c, icolor in bags[color]:
|
||||||
|
r += c * count(icolor)
|
||||||
|
return r
|
||||||
|
|
||||||
|
print(count("shiny gold") - 1)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
data = get_data(__file__)
|
||||||
|
part_1(data)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -137,7 +137,10 @@ Solutions and utility script for Advent of Code challenges in Python.
|
|||||||
- Day 2: 4:47 (no leaderboard, you can tell it's getting faster)
|
- Day 2: 4:47 (no leaderboard, you can tell it's getting faster)
|
||||||
- Day 3: 7:06 (way too slow, lol; time to take it seriously)
|
- Day 3: 7:06 (way too slow, lol; time to take it seriously)
|
||||||
- Day 4: 14:30 (yo, I am just too slow)
|
- Day 4: 14:30 (yo, I am just too slow)
|
||||||
- Day 5:
|
- Day 5: 11:53 (not competitive)
|
||||||
|
- Day 6: 4:11 (75th, finally on the leaderboard)
|
||||||
|
- Day 7: 24:39 (bad)
|
||||||
|
- Day 8:
|
||||||
|
|
||||||
|
|
||||||
## AoC 2022
|
## AoC 2022
|
||||||
|
|||||||
Reference in New Issue
Block a user