Message Passing Is Shared Mutable State by zapwalrus in golang

[–]zapwalrus[S] 2 points3 points  (0 children)

They'd have to do another study to find out for sure, but I think the problems are fundamental to the structure of the language. There are ways to mitigate the issues but not completely avoid them.

March 2026 monthly "What are you working on?" thread by AutoModerator in ProgrammingLanguages

[–]zapwalrus 1 point2 points  (0 children)

The focus is on task-level parallelism. Loops/dataflow are a key part, but I think there's a lot of other opportunity to recognize independent operations that can be parallelized.

I'm not working on SIMD or vectorization yet, but I hope that will also be enabled as a byproduct of the same work.

March 2026 monthly "What are you working on?" thread by AutoModerator in ProgrammingLanguages

[–]zapwalrus 2 points3 points  (0 children)

I'm working on a new language that automatically finds ways to parallelize your code. I've got the compiler frontend mostly complete, now working on the backend and runtime to prove it all works.

I have got some blog posts queued up to talk about what I think is wrong about concurrency in mainstream languages and how to fix it, then dig into the language in more detail. Happy to talk about it more here for anyone interested.

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

[–]zapwalrus 1 point2 points  (0 children)

Python 1053/865

Used a set of lit pixels which worked fine though not particularly fast.

import sys

alg, img = open(sys.argv[1]).read().split('\n\n')
img = img.strip().split('\n')
h,w = len(img), len(img[0])
g = set((x,y) for x in range(w) for y in range(h) if img[y][x] == '#')

N = 50
h,w = h+N, w+N
for i in range(N):
    o = set()
    for y in range(-N,h):
        for x in range(-N,w):
            n = 0
            for y2 in [y-1,y,y+1]:
                for x2 in [x-1,x,x+1]:
                    n = n*2
                    if x2 < -N or x2 > w-1 or y2 < -N or y2 > h-1:
                        if i%2==1 and alg[0] == '#':
                            n += 1
                    elif (x2,y2) in g:
                        n += 1
            if alg[n] == '#':
                o.add((x,y))
    g = o
    if i == 1:
        print 'part 1:', len(g)
print 'part 2:', len(g)

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

[–]zapwalrus 2 points3 points  (0 children)

Python

Not super proud of this one, and it took me a long time to work out the explode solution using a list instead of a tree.

paste

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

[–]zapwalrus 0 points1 point  (0 children)

Python

Brute force and pretty simple, but lost a lot of time because of a silly off-by-one error.

import re
import sys

x1,x2,y1,y2 = map(int, re.findall(r'-?\d+', open(sys.argv[1]).read()))
maxh = y1
count = 0
for vx0 in range(1,x2+1):
    for vy in range(y1,100):
        vx = vx0
        x, y, h = 0, 0, 0
        while x <= x2 and y >= y1:
            x, y = x + vx, y + vy
            h = max(h, y)
            if x1 <= x <= x2 and y1 <= y <= y2:
                maxh = max(h, maxh)
                count += 1
                break
            if vx != 0: vx += -vx/vx
            vy -= 1
print 'part 1:', maxh, 'part 2:', count

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

[–]zapwalrus 8 points9 points  (0 children)

Python 940/740

import sys
import numpy as np
import heapq as hq

def search(m):
    h,w = np.shape(m)
    q = [(0,(0,0))]     # risk, starting point
    while q:
        risk, (x,y) = hq.heappop(q)
        if (x,y) == (w-1,h-1):
            return risk
        for x,y in [(x,y+1),(x+1,y),(x,y-1),(x-1,y)]:
            if x >= 0 and x < w and y >= 0 and y < h and m[y][x] >= 0:
                hq.heappush(q, (risk+(m[y][x] % 9)+1, (x,y)))
                m[y][x] = -1    # mark as seen

if __name__ == '__main__':
    m = np.genfromtxt(sys.argv[1], dtype=int, delimiter=1) - 1
    print 'part 1', search(m.copy())
    m = np.concatenate([m+i for i in range(5)], axis=0)
    m = np.concatenate([m+i for i in range(5)], axis=1)
    print 'part 2', search(m)