year
stringclasses 1
value | day
stringclasses 7
values | part
stringclasses 2
values | pass
stringclasses 15
values | fail
stringclasses 15
values | test
stringclasses 14
values | change
stringclasses 2
values | i1
uint32 2
54
| i2
uint32 6
58
| j1
uint32 2
54
| j2
uint32 6
61
|
---|---|---|---|---|---|---|---|---|---|---|
2022 | day01 | part1 | def solve(test: str) -> str:
numbers = test.strip().splitlines(keepends=False)
maximum = 0
current = 0
for number in numbers:
if number == "":
if current > maximum:
maximum = current
current = 0
continue
current += int(number)
if current > maximum:
maximum = current
return str(maximum)
| def solve(test: str) -> str:
numbers = test.strip().splitlines(keepends=False)
maximum = 0
current = 0
for number in numbers:
if number == "":
if current > maximum:
maximum = current
current = 0
continue
current += int(number)
return str(maximum)
| assert solve('1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n10000') == '24000'
assert solve('1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n100000') == '100000' | insert | 14 | 14 | 14 | 17 |
2022 | day01 | part1 | def solve(test: str) -> str:
chunks = test.strip().split("\n\n")
maximum = 0
for chunk in chunks:
current = 0
numbers = map(int, chunk.splitlines())
for number in numbers:
current += number
if current > maximum:
maximum = current
return str(maximum)
| def solve(test: str) -> str:
chunks = test.strip().split("\n\n")
current = 0
maximum = 0
for chunk in chunks:
numbers = map(int, chunk.splitlines())
for number in numbers:
current += number
if current > maximum:
maximum = current
return str(maximum)
| assert solve('1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n10000') == '24000'
assert solve('1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n100000') == '100000' | replace | 2 | 6 | 2 | 6 |
2022 | day01 | part2 | def solve(test: str) -> str:
chunks = test.strip().split("\n\n")
values = []
for chunk in chunks:
numbers = map(int, chunk.splitlines())
current = 0
for number in numbers:
current += number
values.append(current)
top = sum(sorted(values, reverse=True)[:3])
return str(top)
| def solve(test: str) -> str:
chunks = test.strip().split("\n\n")
values = []
for chunk in chunks:
numbers = map(int, chunk.splitlines())
current = 0
for number in numbers:
current += number
values.append(current)
top = sum(reversed(sorted(values)[:3]))
return str(top)
| assert solve('1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n10000') == '45000'
assert solve('1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n100000') == '135000' | replace | 12 | 13 | 12 | 13 |
2022 | day02 | part1 | def solve(test: str) -> str:
points = {"X": 1, "Y": 2, "Z": 3}
beats = {"X": "C", "Y": "A", "Z": "B"}
mapping = {"X": "A", "Y": "B", "Z": "C"}
lines = test.strip().splitlines(keepends=False)
score = 0
for line in lines:
fst, snd = line.split(" ")
if fst == beats[snd]:
score += 6
elif fst == mapping[snd]:
score += 3
score += points[snd]
return str(score)
| def solve(test: str) -> str:
points = {"X": 1, "Y": 2, "Z": 3}
beats = {"X": "C", "Y": "A", "Z": "B"}
lines = test.strip().splitlines(keepends=False)
score = 0
for line in lines:
fst, snd = line.split(" ")
if fst == beats[snd]:
score += 6
elif fst == snd:
score += 3
score += points[snd]
return str(score)
| assert solve('A Y\nB X\nC Z') == '15' | replace | 3 | 13 | 3 | 14 |
2022 | day02 | part2 | def solve(test: str) -> str:
points = {"A": 1, "B": 2, "C": 3}
beats = {"A": "C", "B": "A", "C": "B"}
loses = {"A": "B", "B": "C", "C": "A"}
lines = test.strip().splitlines(keepends=False)
score = 0
for line in lines:
fst, out = line.split(" ")
if out == "X":
score += points[beats[fst]]
elif out == "Y":
score += 3 + points[fst]
elif out == "Z":
score += 6 + points[loses[fst]]
return str(score)
| def solve(test: str) -> str:
points = {"A": 1, "B": 2, "C": 3}
beats = {"A": "C", "B": "A", "C": "B"}
loses = {"A": "B", "B": "C", "C": "A"}
lines = test.strip().splitlines(keepends=False)
score = 0
for line in lines:
fst, out = line.split(" ")
if out == "X":
score += points[loses[fst]]
elif out == "Y":
score += 3 + points[fst]
elif out == "Z":
score += 6 + points[beats[fst]]
return str(score)
| assert solve('A Y\nB X\nC Z') == '12' | replace | 12 | 17 | 12 | 17 |
2022 | day03 | part1 | import string
def solve(test: str) -> str:
priorities = {
c: v
for v, c in enumerate(string.ascii_lowercase + string.ascii_uppercase, start=1)
}
lines = test.strip().splitlines(keepends=False)
priority = 0
for line in lines:
midpoint = len(line) // 2
part1, part2 = set(line[:midpoint]), set(line[midpoint:])
common = "".join(part1.intersection(part2))
priority += priorities.get(common, 0)
return str(priority)
| import string
def solve(test: str) -> str:
priorities = dict(
enumerate(string.ascii_lowercase + string.ascii_uppercase, start=1)
)
lines = test.strip().splitlines(keepends=False)
priority = 0
for line in lines:
midpoint = len(line) // 2
part1, part2 = set(line[:midpoint]), set(line[midpoint:])
common = "".join(part1.intersection(part2))
priority += priorities.get(common, 0)
return str(priority)
| assert solve('vJrwpWtwJgWrhcsFMMfFFhFp\njqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL\nPmmdzqPrVvPwwTWBwg\nwMqvLMZHhHMvwLHjbvcjnnSBnvTQFn\nttgJtRGJQctTZtZT\nCrZsJsPPZsGzwwsLwLmpwMDw') == '157' | replace | 4 | 7 | 4 | 8 |
2022 | day03 | part2 | import string
def solve(test: str) -> str:
priorities = {
c: v
for v, c in enumerate(string.ascii_lowercase + string.ascii_uppercase, start=1)
}
lines = test.strip().splitlines(keepends=False)
priority = 0
for i in range(0, len(lines), 3):
common = "".join(set(lines[i]) & set(lines[i + 1]) & set(lines[i + 2]))
priority += priorities.get(common, 0)
return str(priority)
| import string
def solve(test: str) -> str:
priorities = {
c: v
for v, c in enumerate(string.ascii_lowercase + string.ascii_uppercase, start=1)
}
lines = test.strip().splitlines(keepends=False)
priority = 0
for i in range(0, len(lines), 3):
common = "".join(set(lines[i]) & set(lines[1]) & set(lines[2]))
priority += priorities.get(common, 0)
return str(priority)
| assert solve('vJrwpWtwJgWrhcsFMMfFFhFp\njqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL\nPmmdzqPrVvPwwTWBwg\nwMqvLMZHhHMvwLHjbvcjnnSBnvTQFn\nttgJtRGJQctTZtZT\nCrZsJsPPZsGzwwsLwLmpwMDw') == '70' | replace | 13 | 14 | 13 | 14 |
2022 | day04 | part1 | def solve(test: str) -> str:
lines = test.strip().splitlines(keepends=False)
result = 0
for line in lines:
int1, int2 = line.split(",", maxsplit=1)
low1, high1 = map(int, int1.split("-", maxsplit=1))
low2, high2 = map(int, int2.split("-", maxsplit=1))
if (low1 <= low2 and high1 >= high2) or (low2 <= low1 and high2 >= high1):
result += 1
return str(result)
| def solve(test: str) -> str:
lines = test.strip().splitlines(keepends=False)
result = 0
for line in lines:
int1, int2 = line.split(",", maxsplit=1)
low1, high1 = map(int, int1.split("-", maxsplit=1))
low2, high2 = map(int, int2.split("-", maxsplit=1))
if max(low1, low2) <= min(high1, high2):
result += 1
return str(result)
| assert solve('2-4,6-8\n2-3,4-5\n5-7,7-9\n2-8,3-7\n6-6,4-6\n2-6,4-8') == '2' | replace | 9 | 10 | 9 | 10 |
2022 | day04 | part2 | def solve(test: str) -> str:
lines = test.strip().splitlines(keepends=False)
result = 0
for line in lines:
int1, int2 = line.split(",", maxsplit=1)
low1, high1 = map(int, int1.split("-", maxsplit=1))
low2, high2 = map(int, int2.split("-", maxsplit=1))
if high1 >= low2 and high2 >= low1:
result += 1
return str(result)
| def solve(test: str) -> str:
lines = test.strip().splitlines(keepends=False)
result = 0
for line in lines:
int1, int2 = line.split(",", maxsplit=1)
low1, high1 = map(int, int1.split("-", maxsplit=1))
low2, high2 = map(int, int2.split("-", maxsplit=1))
if (low1 <= low2 and high1 >= high2) or (low2 <= low1 and high2 >= high1):
result += 1
return str(result)
| assert solve('2-4,6-8\n2-3,4-5\n5-7,7-9\n2-8,3-7\n6-6,4-6\n2-6,4-8') == '4' | replace | 9 | 10 | 9 | 10 |
2022 | day05 | part1 | import string
def solve(test: str) -> str:
configuration, moves = test.split("\n\n", maxsplit=1)
moves = moves.splitlines(keepends=False)
stacks = []
for line in zip(*configuration.splitlines(keepends=False)):
stack = [block for block in reversed(line) if block in string.ascii_uppercase]
if stack:
stacks.append(stack)
for move in moves:
_, count, _, source_stack, _, destination_stack = move.split(" ")
source_stack = int(source_stack) - 1
destination_stack = int(destination_stack) - 1
count = int(count)
for _ in range(count):
crate = stacks[source_stack].pop()
stacks[destination_stack].append(crate)
top_crates = [stack[-1] for stack in stacks]
return "".join(top_crates)
| import string
def solve(test: str) -> str:
configuration, moves = test.split("\n\n", maxsplit=1)
moves = moves.splitlines(keepends=False)
stacks = []
for line in zip(*configuration.splitlines(keepends=False)):
stack = [block for block in line if block in string.ascii_uppercase]
if stack:
stacks.append(stack)
for move in moves:
_, count, _, source_stack, _, destination_stack = move.split(" ")
source_stack = int(source_stack) - 1
destination_stack = int(destination_stack) - 1
count = int(count)
for _ in range(count):
crate = stacks[source_stack].pop()
stacks[destination_stack].append(crate)
top_crates = [stack[-1] for stack in stacks]
return "".join(top_crates)
| assert solve(' [D] \n[N] [C] \n[Z] [M] [P]\n 1 2 3 \n\nmove 1 from 2 to 1\nmove 3 from 1 to 3\nmove 2 from 2 to 1\nmove 1 from 1 to 2') == 'CMZ' | replace | 9 | 10 | 9 | 10 |
2022 | day05 | part2 | import string
def solve(test: str) -> str:
configuration, moves = test.split("\n\n", maxsplit=1)
moves = moves.splitlines(keepends=False)
stacks = []
for line in zip(*configuration.splitlines(keepends=False)):
stack = [block for block in reversed(line) if block in string.ascii_uppercase]
if stack:
stacks.append(stack)
for move in moves:
_, count, _, source_stack, _, destination_stack = move.split(" ")
source_stack = int(source_stack) - 1
destination_stack = int(destination_stack) - 1
count = int(count)
popped = []
for _ in range(count):
crate = stacks[source_stack].pop()
popped.append(crate)
for crate in reversed(popped):
stacks[destination_stack].append(crate)
top_crates = [stack[-1] for stack in stacks]
return "".join(top_crates)
| import string
def solve(test: str) -> str:
configuration, moves = test.split("\n\n", maxsplit=1)
moves = moves.splitlines(keepends=False)
stacks = []
for line in zip(*configuration.splitlines(keepends=False)):
stack = [block for block in reversed(line) if block in string.ascii_uppercase]
if stack:
stacks.append(stack)
for move in moves:
_, count, _, source_stack, _, destination_stack = move.split(" ")
source_stack = int(source_stack) - 1
destination_stack = int(destination_stack) - 1
count = int(count)
popped = []
for _ in range(count):
crate = stacks[source_stack].pop()
popped.append(crate)
for crate in popped:
stacks[destination_stack].append(crate)
top_crates = [stack[-1] for stack in stacks]
return "".join(top_crates)
| assert solve(' [D] \n[N] [C] \n[Z] [M] [P]\n 1 2 3 \n\nmove 1 from 2 to 1\nmove 3 from 1 to 3\nmove 2 from 2 to 1\nmove 1 from 1 to 2') == 'MCD' | replace | 25 | 26 | 25 | 26 |
2022 | day06 | part1 | def solve(test: str) -> str:
for i in range(len(test) - 3):
if len(set(test[i : i + 4])) == 4:
break
return str(i + 4)
| def solve(test: str) -> str:
for i in range(len(test) - 3):
if len(set(test[i : i + 4])) == 4:
break
return str(i)
| assert solve('mjqjpqmgbljsphdztnvjfqwrcgsmlb') == '7'
assert solve('bvwbjplbgvbhsrlpgdmjqwftvncz') == '5'
assert solve('nppdvjthqldpwncqszvftbrmjlhg') == '6'
assert solve('nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg') == '10'
assert solve('zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw') == '11' | replace | 5 | 6 | 5 | 6 |
2022 | day06 | part2 | def solve(test: str) -> str:
for i in range(len(test) - 13):
if len(set(test[i : i + 14])) == 14:
break
return str(i + 14)
| def solve(test: str) -> str:
for i in range(len(test) - 13):
if len(set(test[i : i + 14])) == 14:
break
return str(i)
| assert solve('mjqjpqmgbljsphdztnvjfqwrcgsmlb') == '19'
assert solve('bvwbjplbgvbhsrlpgdmjqwftvncz') == '23'
assert solve('nppdvjthqldpwncqszvftbrmjlhg') == '23'
assert solve('nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg') == '29'
assert solve('zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw') == '26' | replace | 5 | 6 | 5 | 6 |
2022 | day07 | part1 | def calculate_directory_size(directory, cwd, sizes):
size = 0
for name, content in directory.items():
current_name = cwd + name + "/"
if isinstance(content, int):
size += content
else:
size += calculate_directory_size(content, current_name, sizes)
sizes[cwd] = size
return size
def solve(test: str) -> str:
commands = test.lstrip("$ ").strip().split("\n$ ")
cwd = []
filesystem = {"/": {}}
for command in commands:
command = command.splitlines(keepends=False)
command, output = command[0], command[1:]
command = command.split(" ")
command, args = command[0], command[1:]
if command == "cd":
directory = args[0]
if directory == "..":
cwd.pop()
else:
cwd.append(directory)
if command == "ls":
container_directory = filesystem
for cwd_part in cwd:
container_directory = container_directory[cwd_part]
for node in output:
fst, snd = node.split(" ")
if fst == "dir":
container_directory[snd] = {}
else:
container_directory[snd] = int(fst)
sizes = {}
for _, content in filesystem.items():
calculate_directory_size(content, "/", sizes)
total = 0
for _, size in sizes.items():
if size <= 100000:
total += size
return str(total)
| def calculate_directory_size(directory, cwd, sizes):
size = 0
for name, content in directory.items():
current_name = cwd + name + "/"
if isinstance(content, int):
size += content
else:
size += calculate_directory_size(content, current_name, sizes)
sizes[current_name] = size
return size
def solve(test: str) -> str:
commands = test.lstrip("$ ").strip().split("\n$ ")
cwd = []
filesystem = {"/": {}}
for command in commands:
command = command.splitlines(keepends=False)
command, output = command[0], command[1:]
command = command.split(" ")
command, args = command[0], command[1:]
if command == "cd":
directory = args[0]
if directory == "..":
cwd.pop()
else:
cwd.append(directory)
if command == "ls":
container_directory = filesystem
for cwd_part in cwd:
container_directory = container_directory[cwd_part]
for node in output:
fst, snd = node.split(" ")
if fst == "dir":
container_directory[snd] = {}
else:
container_directory[snd] = int(fst)
sizes = {}
for _, content in filesystem.items():
calculate_directory_size(content, "/", sizes)
total = 0
for _, size in sizes.items():
if size <= 100000:
total += size
return str(total)
| assert solve('$ cd /\n$ ls\ndir a\n14848514 b.txt\n8504156 c.dat\ndir d\n$ cd a\n$ ls\ndir e\n29116 f\n2557 g\n62596 h.lst\n$ cd e\n$ ls\n584 i\n$ cd ..\n$ cd ..\n$ cd d\n$ ls\n4060174 j\n8033020 d.log\n5626152 d.ext\n7214296 k') == '95437' | replace | 10 | 11 | 10 | 11 |
2022 | day07 | part2 | def calculate_directory_size(directory, cwd, sizes):
size = 0
for name, content in directory.items():
current_name = cwd + name + "/"
if isinstance(content, int):
size += content
else:
size += calculate_directory_size(content, current_name, sizes)
sizes[cwd] = size
return size
def solve(test: str) -> str:
commands = test.lstrip("$ ").strip().split("\n$ ")
cwd = []
filesystem = {"/": {}}
for command in commands:
command = command.splitlines(keepends=False)
command, output = command[0], command[1:]
command = command.split(" ")
command, args = command[0], command[1:]
if command == "cd":
directory = args[0]
if directory == "..":
cwd.pop()
else:
cwd.append(directory)
if command == "ls":
container_directory = filesystem
for cwd_part in cwd:
container_directory = container_directory[cwd_part]
for node in output:
fst, snd = node.split(" ")
if fst == "dir":
container_directory[snd] = {}
else:
container_directory[snd] = int(fst)
sizes = {}
for _, content in filesystem.items():
calculate_directory_size(content, "/", sizes)
used_space = sizes["/"]
free_space = 70000000 - used_space
required_space = 30000000 - free_space
smallest_directory = None
for directory, size in sizes.items():
if size >= required_space:
if smallest_directory is None or size < sizes[smallest_directory]:
smallest_directory = directory
num = sizes[smallest_directory]
return str(num)
| def calculate_directory_size(directory, cwd, sizes):
size = 0
for name, content in directory.items():
current_name = cwd + name + "/"
if isinstance(content, int):
size += content
else:
size += calculate_directory_size(content, current_name, sizes)
sizes[cwd] = size
return size
def solve(test: str) -> str:
commands = test.lstrip("$ ").strip().split("\n$ ")
cwd = []
filesystem = {"/": {}}
for command in commands:
command = command.splitlines(keepends=False)
command, output = command[0], command[1:]
command = command.split(" ")
command, args = command[0], command[1:]
if command == "cd":
directory = args[0]
if directory == "..":
cwd.pop()
else:
cwd.append(directory)
if command == "ls":
container_directory = filesystem
for cwd_part in cwd:
container_directory = container_directory[cwd_part]
for node in output:
fst, snd = node.split(" ")
if fst == "dir":
container_directory[snd] = {}
else:
container_directory[snd] = int(fst)
sizes = {}
for _, content in filesystem.items():
calculate_directory_size(content, "/", sizes)
used_space = sizes["/"]
free_space = 70000000 - used_space
required_space = 30000000 - free_space
num = None
for num in sizes.values():
if num >= required_space:
break
return str(num)
| assert solve('$ cd /\n$ ls\ndir a\n14848514 b.txt\n8504156 c.dat\ndir d\n$ cd a\n$ ls\ndir e\n29116 f\n2557 g\n62596 h.lst\n$ cd e\n$ ls\n584 i\n$ cd ..\n$ cd ..\n$ cd d\n$ ls\n4060174 j\n8033020 d.log\n5626152 d.ext\n7214296 k') == '24933642'
assert solve('$ cd /\n$ ls\ndir a\n8504156 c.dat\ndir d\n$ cd a\n$ ls\ndir e\n4060174 j\n8033020 d.log\n5626152 d.ext\n7214296 k\n$ cd e\n$ ls\n29116 f\n2557 g\n62596 h.lst\n$ cd ..\n$ cd ..\n$ cd d\n$ ls\n14848514 b.txt\n584 i') == '14849098' | replace | 54 | 58 | 54 | 61 |