Skip to content

pe-solutions/pe-dlang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

350 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dlang Project Euler solutions

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!

Project Euler profile badge for mavotroky


Structure

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.


Building

Single solution — run from inside the problem directory:

cd pe-0001
dub run
dub run --build=release   # optimised

All 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 solution

Run 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 success

Clean all solutions at once:

.\clean-all.ps1                  # remove build artifacts
.\clean-all.ps1 -ShowOutput      # print dub output for every solution

Solution conventions

Every 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.


Further reading

About

Project Euler solutions in Dlang

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors