Skip to content

Instantly share code, notes, and snippets.

View spielkind's full-sized avatar

Reik Keutterling spielkind

  • DTAG
  • Berlin, Germany
View GitHub Profile
#!/bin/python
with open('day11.txt') as f:
octopuses = [list(map(int, list(line.strip()))) for line in f]
def get_neighbours(p):
neighbours = []
(x, y) = p[0], p[1]
if x != 0:
neighbours.append((x-1, y))
#!/bin/python
with open('day10.txt') as f:
lines = [list(line.strip()) for line in f]
bracketpair = {'(': ')', '[': ']', '{': '}', '<': '>'}
points = {')': 3, ']': 57, '}': 1197, '>': 25137}
scores = {')': 1, ']': 2, '}': 3, '>': 4}
illegal = 0
totalscores = []
#!/bin/python
with open('day9.txt') as f:
heightmap = [list(map(int, line.strip())) for line in f]
def get_neighbours(p):
neighbours = []
(x, y) = p[0], p[1]
if x != 0: neighbours.append((x-1, y))
if x != len(heightmap[y])-1: neighbours.append((x+1, y))
#!/bin/python
entries = []
with open('day8.txt') as f:
for line in f:
entry = []
for part in line.strip().split('|'):
entry.append([sorted(list(segments)) for segments in part.strip().split()])
entries.append(entry)
#!/bin/python
with open('day7.txt') as f:
crabs = list(map(int, next(f).strip().split(',')))
pl, ph = min(crabs), max(crabs)+1
fn1 = list(range(ph))
fn2 = {num: num*(num+1)//2 for num in range(ph)}
def opt(fn):
@spielkind
spielkind / day6.py
Last active December 6, 2021 13:53
#!/bin/python
fish = [0] * 9
with open('day6.txt') as f:
for timer in map(int, next(f).strip().split(',')):
fish[timer] += 1
for days in range(256):
nextdayfish = [0] * 9
@spielkind
spielkind / day5.py
Last active December 6, 2021 14:25
#!/bin/python
lines = []
with open('day5.txt') as f:
for line in f:
lines.append([list(map(int, c.strip().split(','))) for c in [p for p in line.strip().split('->')]])
def init_diagram(values):
max_x = max(c[0] for l in values for c in l)+1
max_y = max(c[1] for l in values for c in l)+1
#!/bin/python
with open('day4.txt') as f:
numbers = list(map(int, f.readline().strip().split(',')))
player = -1
bingocards = []
matches = []
for line in f:
if line.strip() == '':
player += 1
@spielkind
spielkind / day3.py
Last active December 3, 2021 19:05
#!/bin/python
with open('day3.txt') as f:
bitslist = [list(map(int, line.strip())) for line in f]
def column(bitslist, location):
return [bits[location] for bits in bitslist]
def bitcount(bitslist, location):
zero_count = column(bitslist, location).count(0)
@spielkind
spielkind / day2.py
Last active December 6, 2021 14:24
#!/bin/python
class Submarine():
def __init__(self):
self.position={'horizontal': 0, 'depth': 0}
self.aim=0
def forward(self,amount):
self.position['horizontal']+=amount
self.position['depth']+=amount*self.aim
def up(self,amount):