Skip to content

Instantly share code, notes, and snippets.

@mfm24
mfm24 / AoC 2021 Day22 part2.py
Last active December 22, 2021 20:16
AoC 2021 Day22 part2
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('..')]
@mfm24
mfm24 / gist:eac71574014a30ff0d3b662f947dd77e
Last active January 11, 2024 07:10
ModuloMathDictionary.py
# 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
@mfm24
mfm24 / ring_condensed.py
Created January 11, 2024 23:04
Ring arithmetic in Python. Condensed version
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):
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"