Compare commits

..

No commits in common. "9e21d8d9c8ad2dd7bb03a36da2fbeed54e414d0b" and "5e782cf3d7109b60fcba0eb9b710896e4158806c" have entirely different histories.

14 changed files with 0 additions and 222 deletions

View File

@ -1,3 +0,0 @@
def parse(filename: str) -> list[tuple[str, str]]:
with open(filename) as f:
return [tuple(a[:-1].split()) for a in f.readlines()]

View File

@ -1,37 +0,0 @@
from common import parse
def round(game: tuple[str, str]) -> int:
if game[0] == "A":
if game[1] == "X":
return 1 + 3
elif game[1] == "Y":
return 2 + 6
else:
return 3 + 0
elif game[0] == "B":
if game[1] == "X":
return 1 + 0
elif game[1] == "Y":
return 2 + 3
else:
return 3 + 6
else:
if game[1] == "X":
return 1 + 6
elif game[1] == "Y":
return 2 + 0
else:
return 3 + 3
def solve(strategy: list[tuple[str, str]]) -> int:
return sum(map(round, strategy))
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()

View File

@ -1,37 +0,0 @@
from common import parse
def round(game: tuple[str, str]) -> int:
if game[0] == "A":
if game[1] == "X":
return 3
elif game[1] == "Y":
return 3 + 1
else:
return 6 + 2
elif game[0] == "B":
if game[1] == "X":
return 1
elif game[1] == "Y":
return 3 + 2
else:
return 6 + 3
else:
if game[1] == "X":
return 2
elif game[1] == "Y":
return 3 + 3
else:
return 6 + 1
def solve(strategy: list[tuple[str, str]]) -> int:
return sum(map(round, strategy))
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()

View File

@ -1 +0,0 @@
# Nothing in common

View File

@ -1,22 +0,0 @@
from string import ascii_lowercase
def parse(filename: str) -> list[tuple[str, str]]:
with open(filename) as f:
return list(map(lambda x: (x[0 : int((len(x) - 1) / 2)], x[int((len(x) - 1) / 2) : -1]), f.readlines()))
def convert(char: str) -> int:
return ord(char) - 96 if char in ascii_lowercase else ord(char) - 38
def solve(bagpacks: list[tuple[str, str]]) -> int:
return sum(map(convert, [(filter(lambda x: x in bagpack[1], bagpack[0])).__next__() for bagpack in bagpacks]))
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()

View File

@ -1,38 +0,0 @@
from string import ascii_lowercase
def parse(filename: str) -> list[tuple[str, str, str]]:
groups = []
i = 0
group = []
with open(filename) as f:
for line in f.readlines():
if i % 3 == 0 and i != 0:
groups.append(group)
group = []
group.append(line[:-1])
i += 1
groups.append(group)
return tuple(groups)
def convert(char: str) -> int:
return ord(char) - 96 if char in ascii_lowercase else ord(char) - 38
def common_character(group: tuple[str, str, str]) -> str:
assert len(group) == 3
b1, b2, b3 = group
return filter(lambda c: c in b2 and c in b3, b1).__next__()
def solve(groups: list[tuple[str, str, str]]) -> int:
return sum(map(convert, map(common_character, groups)))
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()

View File

@ -1,6 +0,0 @@
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw

View File

@ -1,29 +0,0 @@
from __future__ import annotations
import re
from typing import NamedTuple
class Range(NamedTuple):
first: int
last: int
def __contains__(self, other: Range) -> bool:
return self.first <= other.first and self.last >= other.last
def __str__(self):
return f"{self.first}-{self.last}"
def overlaps_with(self, other: Range) -> bool:
return Range(other.first, other.first) in self or Range(other.last, other.last) in self
def parse(filename: str) -> list[tuple[Range, Range]]:
pairs = []
with open(filename) as f:
while line := f.readline():
if match := re.match(r"(\d+)-(\d+),(\d+)-(\d+)", line):
pairs.append(
(Range(int(match.group(1)), int(match.group(2))), Range(int(match.group(3)), int(match.group(4))))
)
return pairs

View File

@ -1,13 +0,0 @@
from common import Range, parse
def solve(input: list[tuple[Range, Range]]) -> int:
return len(list(filter(lambda x: x[0] in x[1] or x[1] in x[0], input)))
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()

View File

@ -1,13 +0,0 @@
from common import Range, parse
def solve(input: list[tuple[Range, Range]]) -> int:
return len(list(filter(lambda x: x[0].overlaps_with(x[1]) or x[1].overlaps_with(x[0]), input)))
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()

View File

@ -1,6 +0,0 @@
2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8

View File

@ -1,5 +1,4 @@
#!/bin/bash #!/bin/bash
day=$1 day=$1
mkdir day${day} mkdir day${day}
cp template/* day${day}
curl -o day${day}/input --cookie ~/AdventOfCode/2022/cookies.txt https://adventofcode.com/2022/day/$day/input curl -o day${day}/input --cookie ~/AdventOfCode/2022/cookies.txt https://adventofcode.com/2022/day/$day/input

View File

@ -1,3 +0,0 @@
def parse(filename: str):
with open(filename) as f:
return [line[:-1] for line in f.readlines()]

View File

@ -1,13 +0,0 @@
from common import parse
def solve(input):
pass
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()