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 itertools import product | |
cmd_blocks = [] # list of (set, cube) | |
for li in open('day22.txt'): | |
# on x=-11..33,y=-6..40,z=-16..37 | |
cmd, rblocks = li.split() | |
xs, ys, zs = rblocks.split(',') | |
# print(xs, ys, zs) | |
xs = [int(x) for x in xs.split('x=')[1].split('..')] | |
ys = [int(x) for x in ys.split('y=')[1].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
# rings.py | |
# module with ring arithmetic and multiplication and powers | |
# Did this a while ago on another machine? And made a github gist | |
from itertools import islice, cycle, tee | |
import random | |
from typing import Any | |
# from https://gist.github.com/mfm24/eac71574014a30ff0d3b662f947dd77e | |
# wrapped in class with `val` property | |
# This class is unnecessary for functionality, but helpful for debugging |
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 itertools import islice, cycle, tee | |
def a(n, dict_class=dict): | |
a, b = tee(cycle(dict_class() for __ in range(n))) | |
for d in islice(a, n): | |
d.update(dict(enumerate(islice(b, n)))) | |
ret = next(b) | |
return ret | |
class IdDict(dict): |
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 hashlib | |
import math | |
import random | |
from functools import lru_cache | |
class SFB: | |
drop_bucket_full = "drop_bucket_full" | |
drop_stochastic = "drop_stochastic" | |
drop_flow_blocked = "drop_flow_blocked" |
OlderNewer