from Leif's Website

The interesting function is repair, which compares the expression for e.g. z11 with the objective adder expression for z11. If we can't find a node with the objective expression, we recurse into the sub-expressions and try repair those.

import sys
from bidict import bidict

gates = {}
nodes = set()

for line in sys.stdin.read().split('\n\n')[1].splitlines():
    a, op, b, _, c = line.split()
    gates[c] = (op, a, b)
    nodes.update((a, b, c))

nodes = sorted(nodes)
x = [p for p in nodes if p[0] == 'x']
y = [p for p in nodes if p[0] == 'y']
z = [p for p in nodes if p[0] == 'z']

def generate_exprs(gates):
    exprs = bidict()
    def go(p):
        if p in exprs:
            return
        if p in x or p in y:
            exprs[p] = (p,)
        else:
            op, a, b = gates[p]
            go(a)
            go(b)
            exprs[p] = (op, *sorted((exprs[a], exprs[b])))
    for p in nodes:
        go(p)
    return exprs

def objective(n):
    if n == 0:
        return ('XOR', ('x00',), ('y00',))
    else:
        return ('XOR', carry(n - 1), ('XOR', (x[n],), (y[n],)))

def carry(n):
    if n == 0:
        return ('AND', ('x00',), ('y00',))
    else:
        return ('OR', ('AND', carry(n - 1), ('XOR', (x[n],), (y[n],))), ('AND', (x[n],), (y[n],)))

def repair(gates, exprs, p, obj):
    def go(p, obj):
        if exprs[p] == obj:
            return
        if (res := exprs.inv.get(obj)):
            return (p, res)
        else:
            op, a, b = gates[p]
            obj_op, obj_a, obj_b = obj
            if op != obj_op:
                raise Exception
            if go(a, obj_a) is None:
                return go(b, obj_b)
            if go(b, obj_b) is None:
                return go(a, obj_a)
            if go(a, obj_b) is None:
                return go(b, obj_a)
            if go(b, obj_a) is None:
                return go(a, obj_b)
            raise Exception
    return go(p, obj)

swaps = []

for i in range(45):
    exprs = generate_exprs(gates)
    match repair(gates, exprs, z[i], objective(i)):
        case (p, q):
            swaps.extend((p, q))
            gates[p], gates[q] = gates[q], gates[p]

print(','.join(sorted(swaps)))
 
Read more... Discuss...

from Micro Dispatch 📡

Working on a new story at work. An endpoint that can process a batch of items. Problem is, this makes logging tricky. How do you log a message for the whole request if it runs into an error? What about if an individual item in the request runs into an error? Decisions, decisions. Been chatting with Copilot about this and it's providing some insightful answers.

Getting used to Jira; I come from an Azure DevOps background. In a lot of ways I think it is better than Azure DevOps, but... there's so much going on here. Azure DevOps, while it doesn't seem to have as much functionality than Jira, seems easier to use precisely because of that.

Jamming to “Today, Tomorrow” by JJ Project. I could listen to this all day.

#Journal #Status #MusicVideo #JJProject #KPop

 
Read more... Discuss...

from sun scriptorium

a lull in the air. patience in the sky between rainfall. softly covered grey, and i, alone in the house. a rare treat. we enjoy the passing river and watch in trepidation as it floods the grounded ones, the falls, hoping despite destruction this might be an end to a years-long drought. hoping the reservoirs catch enough. hoping it feeds what needs to be fed, and the carrionslink of capital stays well away.

i am alone in the house, but grandfather maple outside is being mended. a winter storm blew through on early schedule, before the sunset-plum leaves had a chance to fall, and shattered his trunk. i say mending because the arborist knows, says we can trim away around his scar and let it heal over clean. that it will matter, and grandfather maple can remain sturdy, if shorn, next to this house he loves so much. isn't that the best we can hope for, in these times: to perhaps have a thimbleful of beings who care enough to stitch us into a future where we remain with our loved ones, however changed?

despite letters being the same and words being what we have, writing begins to me to feel like the ship of theseus.

this is not the first instance the fabled ship has sailed through my mind this year (last two years? three, maybe). and writing isn’t the only place i begin to feel battered, mended, grafted, something economic once again. thinking: another blog space (will it work out this time? am i crafting well? will i take on water and sink, from my own taper or from sellouts, yet again?); another city (17 years of regularity sanded down into gangly limbs and learning to walk different streets); another year in the perpetual pandemic (another box of masks, another phone call to doctors to find ones who care enough for precautions, another round of vaccines and reading research that i try to feel hopeful about and can’t); more people cut away, more people met and befriended, friendships strengthened (that’s life, babe); another year learning in this specific way (too slow? not attentive enough? dissatisfied with it and wondering why i keep chewing on it? teeter-totter); another season (sad i will get less than a hundred autumns, maybe ninety if i’m lucky); another moon cycle (oak moon, dark moon, quiet moon, half-cut offerings, trying my best to keep a rhythm and the hollow doesn’t fill anymore); worldbuilding still (same world? different world? layers and layers and spirals and spirals, maybe it’s all the same, but maybe it’s not, and what matters and what doesn’t?').

on the one hand, yes, that’s life, babe. we orbit and pace and flare in a more or less steady rhythm. but, ugh. rhythms should make you feel like dancing, yes?

what i think i mean is: i remember various milestones not feeling quite so damaging. feeling like i was stepping up, speeding down a current, flying along, growing stronger. i mull things over and wonder: was that true? i wonder: what feels different now? why?

a lack of answers. just the same eyes of resin, slow blinking from where i perch at the second story windows as clouds twirl and puff, each different every time, and yet still a cloud, every time.

#wonder #2025dec the 9th

photo of a pale blue-grey sky with faint streaks of pink hinting at the shapes of clouds. the tops of cedars poke along the bottom of the image and a maple silhouette peeks in from the left of the frame. in the top right of the sky shines a tiny silver crescent moon

 
Read more... Discuss...

from nachtSonnen

Es hat sich gelohnt mich heute zur Arbeit zu zwingen. Ich hatte ein ganz zauberhaftes Beratungsgespräch mit einer sehr angenehmen und spannenden Person. Ich glaube ich konnte ein wenig hilfreich sein.

Dann habe ich noch ein positives Feedback zu einem Flyer den ich entworfen habe bekommen. DarĂĽber habe ich mich sehr gefreut.

Die BPD Selbshilfegruppe ist leider ausgefallen. DafĂĽr habe ich die share pics fĂĽr den trA*vent fertig bekommen.

Ein paar Stunden hatte ich richtig gute Laune.

Leider bin ich jetzt wieder völlig erschöpft und will einfach nur noch ins Bett. Mich nervt das so, so wenig belastbar zu sein.

#job #erschöpfung #borderline #adhs

 
Weiterlesen... Discuss...

Join the writers on Write.as.

Start writing or create a blog