I followed the ins and outs of DMD since early 2004 when the "Great Divide" Phobos/Tango debate was still prevalent.
I ❤️ D and mostly Math'n code too!
pe-dlang/
├── pe-common/ # Shared library
│ └── source/euler/
│ ├── common.d # runSolution template
│ ├── math.d # countDivisors, isPrime, sieve, segmentedSieve, nthPrime,
│ │ # reverseDigits, isPalindrome, digitFreq, isPerfectSquare, largestPrimeFactor,
│ │ # mod, fib, fibFirstNDigits, matMul, matVecMul, matPow
│ ├── rat.d # Rat — exact rational arithmetic
│ └── numerics.d # Solver, Method, SolveResult — root-finding
│ # (Newton-Raphson, Brent-Dekker, TOMS 748, ITP)
├── pe-XXXX/ # One DUB package per problem
│ ├── dub.json
│ └── source/
│ ├── app.d
│ └── data/ # optional: problem-given data files (digits, grids, matrices)
├── build-all.ps1 # Build all solutions in one shot
├── run-all.ps1 # Run all solutions in one shot
└── clean-all.ps1 # Clean all solutions in one shot
Each pe-XXXX/ directory is a self-contained DUB package that depends on pe-common via a local path.
Single solution — run from inside the problem directory:
cd pe-0001
dub run
dub run --build=release # optimisedAll solutions at once — run from the repo root:
.\build-all.ps1 # debug build
.\build-all.ps1 -Release # release build
.\build-all.ps1 -ShowOutput # print dub output for every solutionRun all solutions at once:
.\run-all.ps1 # debug build + run
.\run-all.ps1 -Release # release build + run
.\run-all.ps1 -ShowOutput # also print dub build messages on successClean all solutions at once:
.\clean-all.ps1 # remove build artifacts
.\clean-all.ps1 -ShowOutput # print dub output for every solutionEvery app.d follows the same pattern:
// Problem title
// https://projecteuler.net/problem=N
import ...;
import euler.math : ...; // math utilities as needed
import euler.numerics : ...; // root-finding as needed
import euler.common : runSolution;
// helper functions if any
auto solve() {
// ...
return answer;
}
void main() { runSolution!(solve)(N); }runSolution handles the timer and output format:
Project Euler #N
Answer: 12345
Elapsed time: 3 milliseconds.
- Shared library reference —
euler.common,euler.math,euler.numericsAPI - Solutions — full list with approaches
