This file contains hidden or 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
nice = 0 | |
with open('day5.txt', 'r') as f: | |
for word in f.readlines(): | |
# 2 overlapping. | |
for i in range(0, len(word), 1): | |
part = word[i:i+2] | |
if word.count(part) >= 2: | |
break | |
else: | |
continue |
This file contains hidden or 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
grid = [[False for x in range(1000)] for y in range(1000)] | |
with open('day6.txt', 'r') as f: | |
for line in f.readlines(): | |
instructions = line.split() | |
x1, y1 = (int(i) for i in instructions[-3].split(',')) | |
x2, y2 = (int(i) for i in instructions[-1].split(',')) | |
for x, row in enumerate(grid): | |
for y, col in enumerate(row): | |
if x1 <= x <= x2 and y1 <= y <= y2: |
This file contains hidden or 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
visited = [(0, 0)] | |
with open('day3.txt', 'r') as f: | |
s = f.readline() | |
x, y = 0, 0 | |
for direction in s: | |
if direction == '>': | |
x += 1 | |
elif direction == '<': | |
x -= 1 |
This file contains hidden or 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
santa_x, santa_y = 0, 0 | |
robot_x, robot_y = 0, 0 | |
visited_santa = [(santa_x, santa_y)] | |
visited_robot = [(robot_x, robot_y)] | |
with open('day3.txt', 'r') as f: | |
s = f.readline() | |
santas_turn = True | |
for direction in s: | |
if santas_turn: |
This file contains hidden or 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
import json | |
total = 0; | |
def traverse_list(l): | |
global total | |
for item in l: | |
if isinstance(item, int): | |
total += item | |
elif isinstance(item, str): |
This file contains hidden or 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
import json | |
total = 0 | |
def traverse_list(l): | |
global total | |
for item in l: | |
if isinstance(item, int): | |
total += item | |
elif isinstance(item, str): |
This file contains hidden or 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
processed_lines = [] | |
known_keys = [] | |
mapping = {} | |
def is_entire_lhand_known(line): | |
ops = ('OR', 'AND', 'NOT', 'LSHIFT', 'RSHIFT') | |
keys = [] | |
for part in [x.strip() for x in line[:line.index('->')].split()]: | |
if part not in ops and not part.isdigit(): | |
keys.append(part) |
This file contains hidden or 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
ticker = { | |
'children': 3, | |
'cats': 7, | |
'samoyeds': 2, | |
'pomeranians': 3, | |
'akitas': 0, | |
'vizslas': 0, | |
'goldfish': 5, | |
'trees': 3, | |
'cars': 2, |
This file contains hidden or 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
ticker = { | |
'children': 3, | |
'cats': 7, | |
'samoyeds': 2, | |
'pomeranians': 3, | |
'akitas': 0, | |
'vizslas': 0, | |
'goldfish': 5, | |
'trees': 3, | |
'cars': 2, |
This file contains hidden or 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
s = '1321131112' | |
for n in xrange(0, 40): | |
chains = [] | |
chain = s[0] | |
prev = s[0] | |
for index, c in enumerate(s[1:], start=1): | |
if c == prev: | |
chain += c | |
else: |
OlderNewer