Cabinet of Curiosities
const s = "const s = %s;\nconsole.log(s.replace(\"%s\", JSON.stringify(s)));"; console.log(s.replace("%s", JSON.stringify(s)));
A Program That Writes Itself
JavaScript · 1960
// Primality testing with a regular expression. // // The number n becomes a string of n ones. The pattern then asks whether // that string can be cut into two-or-more equal groups of two-or-more — // which is exactly the question of whether n has a non-trivial factor. const composite = /^1?$|^(11+?)\1+$/; const isPrime = (n) => !composite.test("1".repeat(n)); const primes = []; for (let n = 2; primes.length < 12; n++) { if (isPrime(n)) primes.push(n); } console.log(primes.join(" "));
Primes, By Regular Expression
JavaScript · 1998
// The Y combinator: recursion for a language that has none. // // Nothing below names itself. `fact` never says "fact", and yet it recurs. const Y = (f) => ((x) => x(x))((x) => f((...args) => x(x)(...args))); const fact = Y((recur) => (n) => (n <= 1 ? 1 : n * recur(n - 1))); console.log([1, 2, 3, 4, 5, 6].map(fact).join(" "));
Recursion Without a Name
JavaScript · 1969
3 works
Move to the edges to look · W A S D to walk · R to recentre
Shown as a list, because your system asks for reduced motion.