brain

tamnd's digital brain — notes, problems, research

42734 notes

Project Euler Problem 55

If we take 47, reverse and add, 47 + 74 = 121, which is palindromic.

eulermathematicscompetitive-programming
Project Euler Problem 359

An infinite number of people (numbered 1, 2, 3, etc.) are lined up to get a room at Hilbert's newest infinite hotel.

eulermathematicscompetitive-programming
Project Euler Problem 716

Consider a directed graph made from an orthogonal lattice of Htimes W nodes.

eulermathematicscompetitive-programming
Project Euler Problem 383

Let f5(n) be the largest integer x for which 5^x divides n.

eulermathematicscompetitive-programming
Project Euler Problem 826

Consider a wire of length 1 unit between two posts.

eulermathematicscompetitive-programming
Project Euler Problem 564

A line segment of length 2n-3 is randomly split into n segments of integer length (n ge 3).

eulermathematicscompetitive-programming
Project Euler Problem 323

Let y0, y1, y2, dots be a sequence of random unsigned 32-bit integers (i.e.

eulermathematicscompetitive-programming
Project Euler Problem 488

Alice and Bob have enjoyed playing Nim every day.

eulermathematicscompetitive-programming
Project Euler Problem 846

A bracelet is made by connecting at least three numbered beads in a circle.

eulermathematicscompetitive-programming
Project Euler Problem 418

Let n be a positive integer.

eulermathematicscompetitive-programming
Project Euler Problem 113

Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for examp

eulermathematicscompetitive-programming
Project Euler Problem 110

In the following equation x, y, and n are positive integers.

eulermathematicscompetitive-programming
Project Euler Problem 872

A sequence of rooted trees Tn is constructed such that Tn has n nodes numbered 1 to n.

eulermathematicscompetitive-programming
Project Euler Problem 425

Two positive numbers A and B are said to be connected (denoted by "A leftrightarrow B") if one of these conditions holds

eulermathematicscompetitive-programming
Project Euler Problem 176

The four right-angled triangles with sides (9,12,15), (12,16,20), (5,12,13) and (12,35,37) all have one of the shorter s

eulermathematicscompetitive-programming
Project Euler Problem 181

Having three black objects B and one white object W they can be grouped in 7 ways like this: | | | | | | | | |--------|-

eulermathematicscompetitive-programming
Project Euler Problem 847

Jack has three plates in front of him.

eulermathematicscompetitive-programming
Project Euler Problem 489

Let G(a, b) be the smallest non-negative integer n for which operatorname{mathbf{gcd}}Greatest common divisor(n^3 + b, (

eulermathematicscompetitive-programming
Project Euler Problem 34

145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

eulermathematicscompetitive-programming
Project Euler Problem 954

A positive integer is called heptaphobic if it is not divisible by seven and no number divisible by seven can be produce

eulermathematicscompetitive-programming
Project Euler Problem 16

2^{15} = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

eulermathematicscompetitive-programming
Project Euler Problem 24

A permutation is an ordered arrangement of objects.

eulermathematicscompetitive-programming
Project Euler Problem 22

Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, b

eulermathematicscompetitive-programming
Project Euler Problem 26

A unit fraction contains 1 in the numerator.

eulermathematicscompetitive-programming
Project Euler Problem 36

The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.

eulermathematicscompetitive-programming
Project Euler Problem 949

Left and Right play a game with a number of words, each consisting of L's and R's, alternating turns.

eulermathematicscompetitive-programming
Project Euler Problem 43

The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order,

eulermathematicscompetitive-programming
Project Euler Problem 35

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime

eulermathematicscompetitive-programming
Project Euler Problem 41

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once.

eulermathematicscompetitive-programming
Project Euler Problem 21

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).

eulermathematicscompetitive-programming
Project Euler Problem 31

In the United Kingdom the currency is made up of pound (£) and pence (p).

eulermathematicscompetitive-programming
Project Euler Problem 952

Given a prime p and a positive integer n lt p, let R(p, n) be the multiplicative order of p modulo n!.

eulermathematicscompetitive-programming
Project Euler Problem 946

Given the representation of a continued fraction alpha is a real number with continued fraction representation: alpha =

eulermathematicscompetitive-programming
Project Euler Problem 27

Euler discovered the remarkable quadratic formula: n^2 + n + 41 It turns out that the formula will produce 40 primes for

eulermathematicscompetitive-programming
Project Euler Problem 32

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, th

eulermathematicscompetitive-programming
Project Euler Problem 23

A perfect number is a number for which the sum of its proper divisors is exactly equal to the number.

eulermathematicscompetitive-programming
Project Euler Problem 40

An irrational decimal fraction is created by concatenating the positive integers: It can be seen that the 12th digit of

eulermathematicscompetitive-programming
Project Euler Problem 955

A sequence (an){n ge 0} starts with a0 = 3 and for each n ge 0, - if an is a triangle numberA triangle number is a numbe

eulermathematicscompetitive-programming
Project Euler Problem 38

Take the number 192 and multiply it by each of 1, 2, and 3: By concatenating each product we get the 1 to 9 pandigital,

eulermathematicscompetitive-programming
Project Euler Problem 29

Consider all integer combinations of a^b for 2 le a le 5 and 2 le b le 5: If they are then placed in numerical order, wi

eulermathematicscompetitive-programming
Project Euler Problem 944

Given a set E of positive integers, an element x of E is called an element divisor (elevisor) of E if x divides another

eulermathematicscompetitive-programming
Project Euler Problem 950

A band of pirates has come into a hoard of treasure, and must decide how to distribute it amongst themselves.

eulermathematicscompetitive-programming
Project Euler Problem 942

Given a natural number q, let p = 2^q - 1 be the q-th Mersenne number.

eulermathematicscompetitive-programming
Project Euler Problem 17

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 lette

eulermathematicscompetitive-programming
Project Euler Problem 11

In the 20 times 20 grid below, four numbers along a diagonal line have been marked in red.

eulermathematicscompetitive-programming
Project Euler Problem 25

The Fibonacci sequence is defined by the recurrence relation: Fn = F{n - 1} + F{n - 2}, where F1 = 1 and F2 = 1.

eulermathematicscompetitive-programming
Project Euler Problem 42

The nth term of the sequence of triangle numbers is given by, tn = frac12n(n+1); so the first ten triangle numbers are:

eulermathematicscompetitive-programming
Project Euler Problem 20

n! means n times (n - 1) times cdots times 3 times 2 times 1.

eulermathematicscompetitive-programming
Project Euler Problem 39

If p is the perimeter of a right angle triangle with integral length sides, a, b, c, there are exactly three solutions f

eulermathematicscompetitive-programming
Project Euler Problem 12

The sequence of triangle numbers is generated by adding the natural numbers.

eulermathematicscompetitive-programming
Project Euler Problem 15

Starting in the top left corner of a 2 times 2 grid, and only being able to move to the right and down, there are exactl

eulermathematicscompetitive-programming
Project Euler Problem 28

Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: 21 22

eulermathematicscompetitive-programming
Project Euler Problem 19

You are given the following information, but you may prefer to do some research for yourself.

eulermathematicscompetitive-programming
Project Euler Problem 945

We use xoplus y for the bitwise XOR of x and y.

eulermathematicscompetitive-programming
Project Euler Problem 47

The first two consecutive numbers to have two distinct prime factors are: The first three consecutive numbers to have th

eulermathematicscompetitive-programming
Project Euler Problem 30

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: As 1 = 1^4 is

eulermathematicscompetitive-programming
Project Euler Problem 948

Left and Right play a game with a word consisting of L's and R's, alternating turns.

eulermathematicscompetitive-programming
Project Euler Problem 44

Pentagonal numbers are generated by the formula, Pn=n(3n-1)/2.

eulermathematicscompetitive-programming
Project Euler Problem 13

Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.

eulermathematicscompetitive-programming
Project Euler Problem 48

The series, 1^1 + 2^2 + 3^3 + cdots + 10^{10} = 10405071317.

eulermathematicscompetitive-programming
Project Euler Problem 956

The total number of prime factors of n, counted with multiplicity, is denoted Omega(n).

eulermathematicscompetitive-programming
Project Euler Problem 37

The number 3797 has an interesting property.

eulermathematicscompetitive-programming
Project Euler Problem 951

Two players play a game using a deck of 2n cards: n red and n black.

eulermathematicscompetitive-programming
Project Euler Problem 46

It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a s

eulermathematicscompetitive-programming
Project Euler Problem 941

de Bruijn has a digital combination lock with k buttons numbered 0 to k-1 where k le 10.

eulermathematicscompetitive-programming
Project Euler Problem 50

The prime 41, can be written as the sum of six consecutive primes: This is the longest sum of consecutive primes that ad

eulermathematicscompetitive-programming
Project Euler Problem 14

The following iterative sequence is defined for the set of positive integers: - n to n/2 (n is even) - n to 3n + 1 (n is

eulermathematicscompetitive-programming
Project Euler Problem 953

In the classical game of Nim two players take turns removing stones from piles.

eulermathematicscompetitive-programming
Project Euler Problem 943

Given two unequal positive integers a and b, we define a self-describing sequence consisting of alternating runs of as a

eulermathematicscompetitive-programming
Project Euler Problem 33

The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly

eulermathematicscompetitive-programming
Project Euler Problem 18

By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top

eulermathematicscompetitive-programming
Project Euler Problem 45

Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: | | | | | | |------------|-----|---

eulermathematicscompetitive-programming
Runtime building blocks

Inventory of the third-party and home-grown components the C runtime can stand on: GC (BDWGC, MMTk, Perceus), allocator (mimalloc, scudo), coroutines (minicoro), I/O (libuv, libxev), strings, hash tables, JSON/YAML/CSV, HTTP, LLM, FFI.

c-targetresearchmep-45
Build system

Build pipeline: `mochi build` command surface, output layout, amalgamated runtime, cross-compilation via bundled zig cc, APE via cosmocc, WASM via wasi-sdk, content-addressed caching, reproducibility.

c-targetresearchmep-45
C target and portability

The C target itself: C23 features used, compiler matrix (clang, gcc, msvc, zig cc, cosmocc, tcc), tier-1/2/3 architectures and OSes, ABI per arch, libc matrix, sanitisers, reproducibility, hardening, style guide for emitted C.

c-targetresearchmep-45
Design philosophy

The five guiding principles behind the Mochi-to-C transpiler (spec-first, boring C, no ABI surprises, portability over performance, verifiable output), plus the runtime shape and a sample C output.

c-targetresearchmep-45
Type-system lowering

Type-system lowering details: generics/monomorphisation, records, sum types with niche optimisation, closures with fat pointer, strings with SSO, lists, maps with Swiss-table, sets, time/duration, error values with built-in code table.

c-targetresearchmep-45
Codegen design

Codegen pipeline, why a C IR, name mangling rules, type-lowering table, value representation with `mochi_value` boxed type, expression lowering, statement lowering, for-loop lowering, try/catch via setjmp, Maranget pattern matching, modules, amalgamation.

c-targetresearchmep-45
Risks and alternatives

Risks (semantic, build, supply chain, performance, ergonomic), explicit alternatives considered (LLVM IR, WASM, Rust, JIT, C++, Zig), kill switches that demote the transpiler back to optional, comparable industrial precedent.

c-targetresearchmep-45
Language surface

Every Mochi construct the MEP-45 codegen must lower: value core, function core, collection core, ADT core, query DSL, stream/agent core, logic, AI/FFI, tests, modules, error model, concurrency semantics.

c-targetresearchmep-45
Testing and CI gates

Testing strategy: differential testing against vm3, BG corpus, fuzzing, sanitiser matrix (ASan/UBSan/TSan/MSan/LeakSan), property tests, reproducibility check, 16 phased CI gates.

c-targetresearchmep-45
Dataset pipeline lowering

Lowering the Mochi query DSL (LINQ-style from/where/select/join/group by/order/limit/union/intersect/except) to C with arena allocation, operator fusion, and load/save adapters.

c-targetresearchmep-45
Prior-art transpilers

Survey of transpilers and AOT compilers that emit C or behave like a C-target system: Nim, Crystal, Vala, OCaml, Roc, Koka, MLton, Cosmopolitan, zig cc, Cython, ATS, Soufflé. Twelve distilled lessons.

c-targetresearchmep-45
Streams and agents

Lowering Mochi `stream<T>`, stream definitions, `on`-handlers, agent records, and `intent` methods, plus the M:N work-stealing scheduler over minicoro fibers that runs them.

c-targetresearchmep-45
MEP-42 Linker and Runtime Recommendation

One paragraph each, Phase 1 vs Phase 2.

native-codegenlinkers
Code Signing and Notarization

Gatekeeper, notarytool, SmartScreen, Authenticode, and the real cost of shipping a desktop binary.

native-codegenruntime
MEP-42 Phase 1: Naive Backend Recommendation

One-paragraph recommendation, plus reasoning, for which naive-emission technique Mochi MEP-42 should adopt as the first cut.

native-codegennaive
Static-PIE

Statically linked, position-independent, ASLR-friendly, and no dynamic loader required.

native-codegenruntime
The Compile-Time vs Runtime Trade-Off

A conceptual essay on where Mochi MEP-42 should sit on the curve from "compile slowly, run fast" (LLVM -O3) through "compile and run at medium speed" (Cranelift, B3) to "compile instantly, run okay" (copy-and-patch, Sparkplug).

native-codegenpapers
MEP-42 Backend Survey: Summary and Recommendation

Comparison table and Phase 1 / Phase 2 recommendation for Mochi's native code-generation backend.

native-codegenbackends
AOT Compilation Case Studies: Summary for MEP-42

Cross-cutting patterns from twelve production AOT pipelines, with a recommendation for which one Mochi should learn from most.

native-codegenaot
Compiler Textbooks Relevant to a Naive Mochi Backend (2022-2026)

The published material a Mochi engineer should keep open while implementing MEP-42 phase 1. Cooper/Torczon 3rd ed for the canonical theory, Nystrom for a hands-on bytecode compiler walkthrough, Appel for the verified-compiler-curious, plus 2024-2026 course materials covering…

native-codegenpapers
Hostable JIT/AOT Library Survey for Mochi

The "honorable mentions" beyond LLVM/Cranelift/MIR/QBE.

native-codegenbackends
Emitting Object Files Directly for Mochi

What it takes to write a valid ELF/Mach-O/COFF from a backend's raw bytes.

native-codegenbackends
Source Maps and DWARF for WebAssembly

The two competing approaches to debugging Wasm, and why DWARF won inside Chrome.

native-codegendebug
Apple Universal Binaries

Fat Mach-O wrapping arm64 + x86_64, the lipo tool, and the end of x86_64 support.

native-codegenruntime
Mach-O

The Apple object/executable format: macOS, iOS, iPadOS, tvOS, watchOS, visionOS.

native-codegenformats
CodeView and PDB

Microsoft's native debug format, the sidecar PDB file, and the pain of producing one on Linux.

native-codegendebug
PE/COFF

The Windows executable and object format.

native-codegenformats
Mojo

Python-syntax systems language built on MLIR, with both AOT and JIT pipelines, on the path to 1.0 in H1 2026.

native-codegenaot