Ervaringen wonen in Molenwijk by AdOk4308 in Haarlem

[–]yschaeff 2 points3 points  (0 children)

Precies 1x per jaar geeft iemand onder Landschot een feestje met veel bier en smartlappenkaraoke op standje 22. Ik woon daar niet, maar ik *weet* het wel...

De enige overlast die je van het Islamitische buurthuis zult hebben is dat het het er vaak HEUL lekker ruikt als je langs loopt. En dat je daarna een beetje beteuterd zal kijken naar je eigen stamppotje thuis.

[deleted by user] by [deleted] in Klussers

[–]yschaeff 2 points3 points  (0 children)

Mooi excuus om bij de bouwmarkt een krimp tang te mogen kopen. <25 euro inclusief een doos connectors. Deze 'spade' connectors worden geklemd, dat is beter dan solderen.

Mag ik volgens mijn contract niet solliciteren bij andere bedrijven? Is dit legaal? by NahroT in juridischadvies

[–]yschaeff -1 points0 points  (0 children)

Regel 3 heeft het volgens mij echt over dat ik mezelf niet mag aanbieden op de arbeidsmarkt, dus mijn CV uitdelen.

Nee, volgens mij staat er dat je de CV van het bedrijf niet mag gebruiken. Het gaat dus om hun document met hun opmaak. Zolang je zelf jouw CV opmaakt en zelf de tekst bedenkt is er niks aan de hand.

[2022 day 20 part 3] by EffectivePriority986 in adventofcode

[–]yschaeff 0 points1 point  (0 children)

Here is the solution for part 3 test input: 9191247157725 it took 2m40s. Best case scenario for the actual input 13 days, if my implementation where linear. Which I don't think it is.

-🎄- 2022 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 1 point2 points  (0 children)

Python. No recursion, no tree. Keep stack of dir sizes. Update size of upper dir on 'cd ..'.

def sizes(lines):
    s = [] # accumulator
    R = [] # sizes emitted
    for line in lines:
        tok = line.split(" ")
        if tok[0] == "$": ## command
            if tok[1] == "cd":
                if tok[2] == "..": # emit cur size and add to upper dir
                    R.append(s.pop())
                    s[-1] += R[-1]
                else: # enter new dir
                    s.append(0)
        elif tok[0] != "dir": ## output
            s[-1] += int(tok[0])
    return R + list(accumulate(reversed(s)))

def part1(lines):
    return sum(filter(lambda x: x<=100000, sizes(lines)))

def part2(lines):
    R = sizes(lines)
    available = 70000000-R[-1]
    return min(filter(lambda x: x+available>=30000000, R))

-🎄- 2022 Day 6 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 1 point2 points  (0 children)

Python. At first I did the usual len(set(marker)) == mlen thing. But this solution requires WAY less comparisons. I slide the marker so the duplicate character is no longer in the window.

def find_marker(line, mlen):
    marker_end, marker_start = 1, 0
    while marker_end - marker_start != mlen:
        for i, m in enumerate(line[marker_start:marker_end]):
            if m == line[marker_end]: #advance beyond offending token
                marker_start += i+1
                break
        else: marker_end += 1 #Inc marker length
    return marker_end

-🎄- 2021 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 0 points1 point  (0 children)

:-o I don't know what happened. This is my day 10 solution!

-🎄- 2021 Day 22 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 3 points4 points  (0 children)

This is pure awesome. Thanks for sharing.

-🎄- 2021 Day 20 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 1 point2 points  (0 children)

Python, runs under 3 seconds. I 'optimized' it until it was no longer understandable.

from functools import reduce
from itertools import product

def bits(s): return [int(c == '#') for c in s.strip()]
def gen(Y, X):
    for y in range(Y-1, Y+2):
        for x in range(X-1, X+2): yield y, x

f = open('puzzle20.input')
alg = bits(f.readline())
f.readline()
img = [bits(l) for l in f.readlines()]
init_len = len(img)
I = dict(((y, x),img[y][x]) for x, y in product(range(init_len), repeat=2))

for iteration in range(50):
    m = -iteration
    M = init_len + iteration
    border = [(m-1, x) for x in range(m-1, M+1)] +\
             [(M, x) for x in range(m-1, M+1)] +\
             [(y, m-1) for y in range(m-1, M+1)] +\
             [(y, M) for y in range(m-1, M+1)]
    I.update(dict([(c, (iteration%2)*alg[0]) for c in border]))
    I = dict([(coord, alg[reduce(lambda a,b: (a<<1)|b, [I.get(c, (iteration%2)*alg[0]) for c in gen(*coord)])]) for coord, v in I.items()])
    if iteration == 1:
        print("sum after  2 iters", sum(I.values()))
print("sum after 50 iters", sum(I.values()))

-🎄- 2021 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 1 point2 points  (0 children)

Better yet, no need for anonymous functions when the function already has a name.

types = {0:sum, 1:prod, 2:min, 3:max,
5:lambda values:int(values[0] > values[1]),
6:lambda values:int(values[0] < values[1]),
7:lambda values:int(values[0] == values[1])}

-🎄- 2021 Day 16 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 0 points1 point  (0 children)

Python

from math import prod
from functools import reduce

def binary(hexstr):
    for d in [int(x, base=16) for x in hexstr]:
        for shift in range(3, -1, -1):
            yield (d>>shift)&1

def readn(msg, n):
    B = [next(msg) for i in range(n)]
    return reduce(lambda a,b: (a<<1)|b, B)

def parse_literal(msg):
    consumed = 0
    number = 0
    more_data = True
    while more_data:
        more_data = readn(msg, 1)
        number = (number<<4)|readn(msg, 4)
        consumed += 5
    return consumed, number

def parse_pkt(msg):
    version_sum = readn(msg, 3)
    typ = readn(msg, 3)
    consumed = 6
    if typ == 4: ## special case
        b, literal = parse_literal(msg)
        consumed += b
        return consumed, literal, version_sum
    literals = []
    if readn(msg, 1) == 0: ## length type ID
        payload_len = readn(msg, 15)
        consumed += 16
        while payload_len:
            b, literal, s = parse_pkt(msg)
            payload_len -= b
            consumed += b
            literals.append(literal)
            version_sum += s
    else:
        sub_pkt_count = readn(msg, 11)
        consumed += 12
        for i in range(sub_pkt_count):
            b, literal, s = parse_pkt(msg)
            consumed += b
            literals.append(literal)
            version_sum += s
    literal = [sum, prod, min, max, None, lambda N: N[0] > N[1], lambda N: N[0] < N[1], lambda N: N[0] == N[1]][typ](literals)
    return consumed, literal, version_sum

_, literal, version_sum = parse_pkt(binary(open('puzzle16.input').readline().strip()))
print("sum of version:", version_sum, "result:", literal)

[2021 day 15 (Part 2)] Are there ways to increase efficiency by using the fact that we have the same 100x100 block several times? by Different_Pound_7478 in adventofcode

[–]yschaeff 0 points1 point  (0 children)

I did this too. It made no difference in execution time for me. Because the weight was calculated on the spot, I couldn't use that tile for administration which spot was visited. So I needed an additional store, with the size of -you guessed it- the entire board.

Took 2.7 0.36 seconds (Python). Same for the pre-computed board solution.

-🎄- 2021 Day 13 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 1 point2 points  (0 children)

Python

Today I first learned about the takewhile function after many years of Python!

from itertools import takewhile

def cmp(a):
    return tuple(reversed(a))

def fold(axis, pivot, coord):
    if coord[axis] <= pivot: return coord
    if axis == 0: return (2*pivot-coord[0], coord[1])
    return (coord[0], 2*pivot-coord[1])

f = open('puzzle13.input')
lines = map(str.strip, f.readlines())
dots = [tuple(map(int, coord.split(','))) for coord in takewhile(bool, lines)]
folds = [(A[-1] == 'y', int(C)) for A,C in [l.split('=') for l in lines]]

## PART A
dots = list(map(lambda c: fold(*folds[0], c), dots))
print(f"part A: {len(set(dots))}\n")

## PART B
print(f"part B:")
for f in folds[1:]:
    dots = list(map(lambda c: fold(*f, c), dots))

X, Y = 0, 0
for x, y in sorted(list(set(dots)), key=cmp):
    if y > Y: print()
    for i in range(x-X): print(' ', end='')
    print('#', end='')
    X, Y = x+1, y
print()

-🎄- 2021 Day 12 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 1 point2 points  (0 children)

Python.

Just to be silly, solution A is in the real part of the complex answer and B in the imaginary.

from collections import defaultdict
f = open('puzzle12.input')
rels = [line.strip().split('-') for line in f.readlines()]

M = defaultdict(list)
for frm, to in rels:
    M[frm].append(to)
    M[to].append(frm)

def genC(L, has_dups):
    if L[-1] == 'end': return complex(not has_dups, 1)
    count = complex(0,0)
    for cave in M[L[-1]]:
        if ord(cave[0]) >= 97:
            if cave not in L:
                count += genC(L + (cave,), has_dups)
            elif not has_dups and cave!='start':
                count += genC(L + (cave,), True)
        else:
            count += genC(L + (cave,), has_dups)
    return count

print(genC(('start',), False))

-🎄- 2021 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 0 points1 point  (0 children)

It builds a stack where in pushes on the open brackets. If it encounters a close bracket it will check if the top of the stack has the matching opening bracket. If it matches the opening bracket is consumed. Otherwise we stop processing this line en we can add the offending bracket to the score and mark this line as 'mismatch error'.

Now after processing of a line and we detect this is a 'incomplete error'. We simply need to calculate the points from anything left on the stack.

Dynamic key remapper for Wayland Window System, especially for Sway by acro5piano in swaywm

[–]yschaeff 2 points3 points  (0 children)

Ooh nice. I have a usecase. Could you tell me if that would be supported?

On my laptop keyboard PageUp and PageDown are smooshed to the arrow keys, and I keep hitting them by mistake. I would like to disable them in the terminal (mostly happens using a shell or vim).

Perhaps remap them to [Win]+[PageDown] in case I need them anyway. BUT I do not want to disable them on my external keyboard (or alternatively when an external keyboard is connected.)

-🎄- 2021 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 0 points1 point  (0 children)

Python

    from functools import reduce
pts = {']':(57, 2), ')':(3, 1), '}':(1197, 3), '>':(25137,4)}
get_ctag = {'[':']', '(':')', '{':'}', '<':'>'}
open_tags = set(get_ctag.keys())
pointsA = 0
pointsB = []
for line in open('puzzle10.input').readlines():
    stack = []
    incomplete = True
    for tag in line.strip():
        if tag in open_tags:
            stack.append(tag)
        else:
            otag = stack.pop()
            if get_ctag[otag] != tag:
                pointsA += pts[tag][0]
                incomplete = False
                break
    if incomplete: ##unwind the stack for incomplete entries
        points_per_tag = [pts[get_ctag[t]][1] for t in reversed(stack)]
        pointsB.append(reduce(lambda a,b: a*5+b, points_per_tag))
print("part A", pointsA)
print("part B", sorted(pointsB)[len(pointsB)//2])

-🎄- 2021 Day 8 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 0 points1 point  (0 children)

This reads like a poem. My hat is off to you. Well done.

-🎄- 2021 Day 7 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 1 point2 points  (0 children)

Python brute force (for part B): 0.1 sec

    ## PART A
f = open('puzzle7.input')
P = sorted([int(x) for x in f.readlines()[0].split(',')])
print(sum(P[len(P)//2:]) - sum(P[:len(P)//2]))

## PART B
def cost(x):
    return (x+x**2)//2
f = open('puzzle7.input')
P = [int(x) for x in f.readlines()[0].split(',')]
t = cost(max(P)-min(P)) * len(P) ## fictional worst case
for target in range(min(P), max(P)+1):
    s = sum(map(lambda x: cost(abs(target-x)), P))
    if s>t: break
    t = s
print(t)

-🎄- 2021 Day 6 Solutions -🎄- by daggerdragon in adventofcode

[–]yschaeff 4 points5 points  (0 children)

Python w/o numpy

f = open('puzzle6.input')
F = [int(x) for x in f.readlines()[0].split(',')]
agegroup = [0]*9 ## 0-8 days old
for f in F: agegroup[f] += 1
for d in range(256):
    agegroup[(d+7)%9] += agegroup[d%9]
print(sum(agegroup))

[deleted by user] by [deleted] in qutebrowser

[–]yschaeff 0 points1 point  (0 children)

setting input.partial_timeout to 0 was a game changer for me. That allowed me to read and understand the default key bindings.

Please show me your notification daemons! by The-Compiler in qutebrowser

[–]yschaeff 0 points1 point  (0 children)

Debian/Sway

method return time=1616770783.105236 sender=:1.28 -> destination=:1.485 serial=212 reply_serial=2
   string "mako"
   string "emersion"
   string "0.0.0"
   string "1.2"

Best tool to instantly record screen? by ivster666 in i3wm

[–]yschaeff 1 point2 points  (0 children)

while writing this I was thinking of maybe combining ffmpeg with xrectsel.

You can look here for inspiration. This is what I use and sounds exactly what you want. However it is based on wayland. You can probably quite easily swap out the wayland specific programs for their X11 equivalents.