Skip to content

DzikowskiW/AoC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code

Disclaimer

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.

Notes

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

Resources

  1. Advent of Code subreddit
  2. Jonathan Paulson Youtube channel - screecasts of solving tasks in Python by a profficient dev
  3. Eric Wastl Twitter - Twitter of Advent of Code creator

VS Code shortcuts

  1. Use Code Runner Extension.
    1. alt + ctrl + N - Run current file
    2. alt + ctrl + M - Stop current process
  2. F5 - start a debugger

Python tips & tricks

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

Parsing input

  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)

About

my Advent of Code solutions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published