Skip to content

Instantly share code, notes, and snippets.

#lang racket/base
(define (build-jumps code)
(define code-len (string-length code))
(define jumps (make-hash))
(define stack '())
;; precompute jumps
(for ([i (in-range code-len)])
(define c (string-ref code i))
@thedeemon
thedeemon / aoc2025_day9part2.swift
Last active February 23, 2026 11:51
translated from Python version
import Foundation
struct Point {
let x: Int
let y: Int
}
struct Border {
let bx: Int
let up: Bool
@thedeemon
thedeemon / aoc2025_day9part2.py
Created February 23, 2026 10:42
Direct translation from .e1 original
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
import sys
@dataclass
class Point:
x: int
y: int
--https://adventofcode.com/2025/day/9
-- Timing on my machine (Intel i7-10710U):
-- When run directly via "e1 prog.e1" ("interpreted" mode): 42.9 seconds
-- When compiled via Racket ("e1 --rkt prog.e1; raco exe prog.rkt"): 14.5 seconds
-- When translated into Python
-- https://gist.github.com/thedeemon/d8df30420f3e57bcb853250b6c06ab5c
-- Python 3.12.10: 513.5 seconds
-- Python 3.14.2: 262.9 seconds
-- Translated to Swift: 2.1 seconds
// Formats only the changed lines mentioned in "git diff".
// Removes trailing whitespace and in leading whitespace converts tabs to spaces.
// Made with Codex.
import Foundation
struct ParsedDiff {
let files: [FileChange]
}
type Maybe a = Some { value : a } | None
class Conv a b {
$ : a -> b
}
instance Conv a String where Show a {
$ = show
}
import Foundation
struct Complex {
var re: Double
var im: Double
static func +(lhs: Complex, rhs: Complex) -> Complex {
Complex(re: lhs.re + rhs.re, im: lhs.im + rhs.im)
}
@thedeemon
thedeemon / Iter.e1
Last active January 21, 2026 15:02
class Iterator it -> a {
next : it -> Maybe a
}
type IotaIter {
mut cur : Int
end : Int
}
instance Iterator IotaIter Int {
-- What works now as of March 12, 2026.
-- Comments start with -- and go until the end of line.
-- Any combination of +-*/<>=:%^&|!~$?# is an operator.
-- But these are part of language syntax: | => -> = :
-- Identifiers start with a lowercase letter and then may have
-- letter, digits, _ and ?.
-- Type names and data constructors start with an uppercase letter
// Integrate timelike geodesics in the equatorial plane (θ = π/2) of a Schwarzschild spacetime
// -----------------------------------------------------------------------------
// Units: c = G = 1. Mass M is given in the same geometric units (Schwarzschild radius r_s = 2M).
// Coordinates: (t, r, φ) with affine parameter λ.
// State vector y = (t, r, φ, 𝑡̇, ṙ, φ̇) where dots denote d/dλ.
// -----------------------------------------------------------------------------
import Foundation
/// Complete phase–space state of a particle on the geodesic
struct State {