This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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): |
NewerOlder