This repo is a collection of my Advent of Code solutions. Some of them are polished, but some are just a dump of messy code that produced a correct solution.
Lately I find Python to be the best language to efficiently do the job. Besides Advent of Code I rarely if ever use Python over the year, so as I write this I am starting to document what I should remember before staring next year's Advent of Code
- Advent of Code subreddit
- Jonathan Paulson Youtube channel - screecasts of solving tasks in Python by a profficient dev
- Eric Wastl Twitter - Twitter of Advent of Code creator
- Use Code Runner Extension.
alt + ctrl + N
- Run current filealt + ctrl + M
- Stop current process
- F5 - start a debugger
defaultdic - Dictionary with default value
parts = defaultdict(list)
parts['foo'].append('bar)
a = defaultdict(int)
d = defaultdict(set)
enumerate()
- adds index to for loop, use start
flag to start from other value than 0
for count, value in enumerate(values):
...
math.prod
- multiplies array values
a = [1, 2, 3, 4]
print(mathprod(a)) # 24
@functools.cache
- memoization of function results, documetation link
import functools
@functools.cache
def factorial(n):
return n * factorial(n-1) if n else 1
intertools - useful library for efficient looping documentation link
for i, line in enumerate(lines, start=1):
(p1, p2) = line.split('|')
i, *winning = list(map(int,re.findall(r'(\d+)', p1)))
mine = list(map(int,re.findall(r'\d+', p2)))
re.finditer()
- creates iterable list of matches
matches = re.finditer(pattern, s)
for match in matches:
print(match)