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
BEGIN MESSAGE. | |
65hLapBEOn4NOxF egwcqIO20ortY0d na6S7EY81Qh8tCs QSLVmAVHIqqn3ad | |
h29hB5xx5GvRGgE aVFTWvLjWLkTCKq 6Xr2MZHgg6SdpCJ TM9zHVJotbsq3wI | |
lAtXO8mikSV1xga sUzGicn8NsMBiUU nTW4dABMOWXRxE1 nbIuenrRNb9lyhP | |
vCe0UMMbuselAJl g3V2jeGTpVJPxt6 UtPtN0Qz5Z. | |
END MESSAGE. |
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
import numpy as np | |
from scipy.ndimage import convolve | |
lines = INPUT.splitlines() | |
alg = [i for i, c in enumerate(lines[0]) if c == "#"] | |
img = np.pad(np.array([[int(c == "#") for c in l] for l in lines[2:]]), ((50, 50), (50, 50))) | |
rot = np.array([[1, 2, 4], [8, 16, 32], [64, 128, 256]]) | |
for i in range(50): | |
img = np.isin(convolve(img, rot, mode="constant", cval=i % 2), alg).astype(int) |
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 convert(l, d=0): | |
for i, e in enumerate(l): | |
if isinstance(e, list): | |
yield from convert(e, d + 1) | |
else: | |
yield (e, d) | |
def reduce(l): | |
c = list(l) |
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 utils import Pt, Grd | |
import math | |
grd = Grd() | |
for i, l in enumerate(LINES): | |
for j, c in enumerate(l): | |
grd[Pt(i, j)] = int(c) | |
def expand(pt): |
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
import { promises } from "fs"; | |
import crypto from "crypto"; | |
import path from "path"; | |
import { print, parse } from "graphql"; | |
const plugin = { | |
name: "relay", | |
setup: build => { | |
build.onLoad({ filter: /\.tsx$/, namespace: "" }, async args => { | |
let contents = await promises.readFile(args.path, "utf8"); |
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
import collections | |
all_ingredients = collections.Counter() | |
possible_ingredients = collections.defaultdict(set) | |
for line in open("inputs/day21").read().splitlines(): | |
ingredients, allergens = line.rstrip(")").split(" (contains ") | |
ingredients = ingredients.split() | |
allergens = allergens.split(", ") | |
all_ingredients.update(ingredients) |
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
import functools | |
import operator | |
import itertools | |
import networkx | |
import numpy as np | |
tiles = {} | |
for tiledata in open("inputs/day20").read().strip().split("\n\n"): | |
a, *tilelines = tiledata.splitlines() |
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
class ParseError(Exception): | |
pass | |
def parse_rule(alts): | |
def parse(inp): | |
for rule in alts: | |
s = inp | |
for el in rule: | |
try: | |
s = rules[el](s) |
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
class a(int): | |
def __mul__(self, b): | |
return a(int(self) + b) | |
def __add__(self, b): | |
return a(int(self) + b) | |
def __sub__(self, b): | |
return a(int(self) * b) | |
def ev(expr, pt2=False): | |
expr = re.sub(r"(\d+)", r"a(\1)", expr) |
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
import numpy as np | |
from scipy.ndimage import convolve | |
LINES = open("inputs/day17").read().splitlines() | |
dims = 3 # 4 for part 2 | |
steps = 6 | |
front = 2 * steps + 1 | |
filt = np.full((3,) * dims, 1) | |
filt[(1,) * dims] = 100 |
NewerOlder