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
04e56764616f40a379b3ca6f7d0ddc83fee6450a72164e53045b7e8159b33ebef90df5e52261c367a9a1820eb55d2e023fa5859d84daf7e524173f50dfee4debae;pablasso |
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
if __name__ == '__main__': | |
with open('input.txt') as data: | |
last = None | |
increased = 0 | |
sum_window = 0 | |
window = [] | |
count = 0 | |
for line in data: | |
value = int(line) | |
sum_window += value |
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
if __name__ == '__main__': | |
with open('input.txt') as data: | |
one_counts = [] | |
total = 0 | |
for line in data: | |
line = line.strip() | |
if len(one_counts) == 0: | |
one_counts = [0] * len(line) | |
for idx, char in enumerate(line): | |
if char == '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
COUNT = 0 | |
DATA = 1 | |
class Trie: | |
def __init__(self): | |
self.root = Node() | |
def add_string(self, string): | |
node = self.root | |
for char in string: | |
node = node.add(char) |
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
BINGO_SIZE = 5 | |
class Bingo: | |
def __init__(self): | |
self.column_count = [0] * BINGO_SIZE | |
self.row_count = [0] * BINGO_SIZE | |
self.data = [] | |
self.index = {} | |
self.called = set() |
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
from collections import defaultdict | |
def key(x, y): | |
return "{0}-{1}".format(x, y) | |
def walk(grid, from_x, from_y, to_x, to_y): | |
grid[key(from_x, from_y)] += 1 | |
while from_x != to_x or from_y != to_y: | |
if from_x < to_x: | |
from_x += 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
def simulate(lanternfish, days): | |
new_lanternfish = [0] * 9 | |
for i in range(days): | |
new_hatched = lanternfish[8] | |
for i in range(1, 9): | |
new_lanternfish[i] = lanternfish[i - 1] | |
new_lanternfish[0] = new_hatched | |
new_lanternfish[2] += new_hatched | |
tmp = lanternfish | |
lanternfish = new_lanternfish |
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
def a_minus_b(a, b): | |
output = [] | |
for char in a: | |
if char in b: | |
continue | |
output.append(char) | |
return output | |
def solve(train_data): | |
digits = train_data.split(' ') |
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
def is_low_point(heights, x, y): | |
adjacent = [] | |
if x > 0: | |
adjacent.append(heights[y][x - 1]) | |
if x < len(heights[y]) - 1: | |
adjacent.append(heights[y][x + 1]) | |
if y > 0: | |
adjacent.append(heights[y - 1][x]) | |
if y < len(heights) - 1: | |
adjacent.append(heights[y + 1][x]) |
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
scores = { | |
')': 3, | |
']': 57, | |
'}': 1197, | |
'>': 25137 | |
} | |
expected = { | |
'(': ')', |