Skip to content

Instantly share code, notes, and snippets.

@sjolsen
sjolsen / permute_words.py
Created March 14, 2024 06:47
word permutations
import collections
import dataclasses
import sys
from typing import Iterable, Self
IGNORED_WORDS: frozenset[str] = frozenset([
'adv',
'dis',
'eds',
@sjolsen
sjolsen / fork_fd.c
Created June 29, 2024 03:42
demonstrating shared file description state across fork
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
int write_all(int fd, const void *buf, size_t count) {
const char *cbuf = (const char *)buf;
@sjolsen
sjolsen / rocket_fuel.py
Last active December 19, 2024 05:43
An example of how to design Factorio factories using linear algebra
"""An example of how to design Factorio factories using linear algebra.
This program computes the number of oil refineries, chemical plants, and
assembly machine 2s needed to convert an abundant supply of crude oil and water
into 1.33 rocket fuel per second, the rate needed to satisfy one rocket silo in
the base game, not including modules.
Two abstract vector spaces are constructed: one representing products, and one
representing recipes. Each recipe is associated with a balanced equation over
products. By expressing this association as a matrix, we can express the