Skip to content

Instantly share code, notes, and snippets.

View vadim2404's full-sized avatar
🏠
Working from home

Vadim Kharitonov vadim2404

🏠
Working from home
View GitHub Profile
@vadim2404
vadim2404 / day14_part1.py
Created December 18, 2023 21:13
day14.py
#!/usr/bin/env python3
from collections import defaultdict
from heapq import heappop, heappush
with open("input.txt") as f:
empty, rocks, walls = defaultdict(list), defaultdict(list), defaultdict(list)
n = 0
@vadim2404
vadim2404 / day13_part2.py
Created December 18, 2023 12:44
day13_part2.py
#!/usr/bin/env python3
def solve(pattern: list[str]) -> int:
n = len(pattern)
m = len(pattern[0])
rows = []
repeated_rows = []
for i in range(n):
x = 0
@vadim2404
vadim2404 / day12_part2.py
Created December 15, 2023 21:49
day12_part2.py
#!/usr/bin/env python3
from functools import cache
def solve(pattern: str, groups: list[int]) -> int:
@cache
def dp(start_pos: int, g: int) -> int:
if start_pos == len(pattern):
return int(g == len(groups))
@vadim2404
vadim2404 / day11_part2.py
Last active December 15, 2023 17:26
day11_part2.py
#!/usr/bin/env python3
def build_map() -> list[list[str]]:
with open("input.txt") as f:
rows = []
for line in f:
line = list(line.strip())
elems = set(line)
if len(elems) == 1 and '.' in elems:
@vadim2404
vadim2404 / day10_part2.py
Last active December 15, 2023 16:16
day10_part2.py
#!/usr/bin/env python3
from typing import Mapping
FROM_TO_MAPPING: Mapping[tuple[int, int], Mapping[str, tuple[int, int]]] = {
(0, 2): {
'-': (0, 2),
'J': (-2, 0),
'7': (2, 0),
@vadim2404
vadim2404 / day9_part1.py
Last active December 15, 2023 10:21
day9
#!/usr/bin/env python3
def solve(arr: list[int]) -> int:
n = len(arr)
x = [arr]
for i in range(n - 1):
x.append([x[i][j + 1] - x[i][j] for j in range(n - i - 1)])
x[-1].append(0)
for i in range(n - 2, -1, -1):
x[i].append(x[i][-1] + x[i + 1][-1])
#!/usr/bin/env python3
import re
from itertools import cycle
map = {}
ROUTE = re.compile(r"^(\w{3}) = \((\w{3}), (\w{3})\)$")
index_map = {
'L': 0,
#!/usr/bin/env python3
from collections import Counter
from enum import IntEnum
from typing import Mapping, Tuple
CARDS: Tuple[str, ...] = ('J', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'Q', 'K', 'A', )
CARDS_VALUES: Mapping[str, int] = {c: i for i, c in enumerate(CARDS, start=2)}
#!/usr/bin/env python3
with open("input.txt") as f:
seeds = [int(x) for x in f.readline().strip().split(':')[1].split(' ') if x]
f.readline()
steps = []
#!/usr/bin/env python3
from typing import Set
def str_to_set(numbers: str) -> Set[int]:
return set(int(x) for x in numbers.strip().split(" ") if x)
ans = 0