I hereby claim:
- I am haakonvt on github.
- I am haakonvt (https://keybase.io/haakonvt) on keybase.
- I have a public key ASCKScJBeabR-d6Ksugx9jRD1PHadTu48f0MW-LHlteGzQo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
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, |
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: |
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): |
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 |
# 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)) |
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)) |
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) |
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: |
# -------- # | |
# 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)) |