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 math | |
from functools import reduce | |
from itertools import count, repeat | |
def reindeer(s): | |
return reduce(lambda i,c: (17*(i+ord(c)))%256, s, 0) | |
# Solution, part 1: | |
sum(map(reindeer, inp.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
# -------- # | |
# Part One # | |
# -------- # | |
def find_slices(col): | |
slices = [] | |
fixed = np.argwhere(col == "#").ravel() | |
for start, end in zip(fixed+1, fixed[1:]): | |
if end > start: | |
slices.append(slice(start, end)) |
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 | |
grids = [np.array(list(map(list, grid.splitlines()))) for grid in inp.split("\n\n")] | |
def is_reflection(arr, col): | |
a1, a2 = arr[:, :col], np.fliplr(arr[:, col:]) | |
l1, l2 = a1.shape[1], a2.shape[1] | |
if l1 > l2: | |
return np.all(a2 == a1[:,-l2:]) | |
else: |
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.spatial.distance import cdist | |
def dist_calc(expansion): | |
grid = np.array(list(map(list, inp.splitlines())), dtype="U1") | |
cols = np.nonzero(np.all(grid == ".", axis=0))[0] | |
rows = np.nonzero(np.all(grid == ".", axis=1))[0] | |
locs = np.argwhere(grid == "#") | |
locs[:, 0] += expansion * np.sum([locs[:, 0] > r for r in rows], axis=0) | |
locs[:, 1] += expansion * np.sum([locs[:, 1] > c for c in cols], axis=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
def diff_inplace(arr): | |
for idx in range(arr.shape[1], 2, -1): | |
arr[:,:idx-1] = np.diff(arr[:,:idx]) | |
return arr.sum() | |
p1 = np.array([l.split() for l in inp.splitlines()], dtype=np.int32) | |
p2 = np.fliplr(p1.copy()) | |
print(diff_inplace(p1), diff_inplace(p2)) |
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
# Part 1: | |
from collections import Counter | |
ranks = [] | |
vals = dict(zip("AKQJT98765432", reversed(range(13)))) | |
for hand, bid in ((h, int(b)) for h, b in (l.split() for l in inp.splitlines())): | |
match Counter(hand).most_common(2): | |
case [(c, 5), *_]: | |
ranks.append((7, *map(vals.get, hand), bid)) |
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 re | |
from math import floor, ceil, prod | |
from more_itertools import chunked | |
from sympy import Symbol, S, solve_univariate_inequality | |
t = Symbol("t", domain=S.Naturals) | |
def to_range(conditions): | |
ineq1, ineq2 = conditions.args | |
if ineq1.lhs == t: # rule: lhs < rhs |
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 Interval: | |
__slots__ = ("start", "end") | |
def __init__(self, start, end): | |
self.start = start | |
self.end = end | |
def __add__(self, n): | |
return Interval(self.start + n, self.end + n) | |
def __repr__(self): |
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 typing import Any, Dict, List, NoReturn, TYPE_CHECKING, Union | |
from kedro.io.core import AbstractDataSet, DataSetError | |
from cognite.client import CogniteClient | |
from cognite.client.config import ClientConfig | |
from cognite.client.data_classes import ClientCredentials | |
from cognite.client.credentials import OAuthClientCredentials | |
from cognite.client.exceptions import CogniteNotFoundError | |
if TYPE_CHECKING: |
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 timeit import default_timer as timer | |
import cognite.client.proto.data_point_list_response_pb2 as ProtobufDataPointList | |
from cognite.client.data_classes import Datapoints | |
payload = dict( | |
start=32760000000-1, | |
end=1638000000000, | |
ignoreUnknownIds=False, |
NewerOlder