import aoc_util input_lines = aoc_util.get_puzzle_lines("6") class Position: def __init__(self, x, y): self.x = int(x) self.y = int(y) def get_start_and_end(position): (s, e) = position.split(' through ') start = Position(*s.split(',')) end = Position(*e.split(',')) return (start, end) w, h = 1000, 1000 grid = [[False for x in range(w)] for y in range(h)] def parse_line(line): value_to_set = False toggle_lights = False if line[:8] == 'turn on ': (start, end) = get_start_and_end(line[8:]) value_to_set = True elif line[:9] == 'turn off ': (start, end) = get_start_and_end(line[9:]) value_to_set = False elif line[:7] == 'toggle ':
import aoc_util import copy from PIL import Image input_string = aoc_util.get_puzzle_lines("18") grid = [[False] + [y == "#" for y in line.rstrip()] + [False] for line in input_string] grid_size = len(grid) grid = [[False] * (grid_size + 2)] + grid + [[False] * (grid_size + 2)] def print_grid(grid): print("\n".join([ "".join("#" if grid[y][x] else "." for x in range(1, grid_size + 1)) for y in range(1, grid_size + 1) ])) print(sum(sum([1 for y in row if y]) for row in grid)) def sum_neighbors(y, x): return (grid[y - 1][x - 1] + grid[y][x - 1] + grid[y + 1][x - 1] + grid[y - 1][x] + grid[y + 1][x] + grid[y - 1][x + 1] + grid[y][x + 1] + grid[y + 1][x + 1]) new_grid = copy.deepcopy(grid) def toggle(y, x): neighbors = sum_neighbors(y, x)
import re import aoc_util input_string = [l.rstrip() for l in aoc_util.get_puzzle_lines("25")][0] print(input_string) regex = r'To continue, please consult the code grid in the manual. Enter the code at row ([\d]+), column ([\d]+).' (r, c) = re.match(regex, input_string).groups() row = int(r) column = int(c) print(row, column) triangle_base = row + column triangle_height = triangle_base - 1 position_in_sequence = int( (triangle_base * triangle_height) / 2) - (row - 1) - 1 print((pow(252533, position_in_sequence, 33554393) * 20151125) % 33554393) row_counter = 1 column_counter = 1 value = 20151125 while True: if row_counter == row and column_counter == column: print('value is', value) break else: value = value * 252533 % 33554393 if row_counter == 1: row_counter = column_counter + 1 column_counter = 1 else: