- Notifications
You must be signed in to change notification settings - Fork0
My solutions to some Project Euler problems. Emphasis on elegance (where possible) and performance.
License
tfpf/project-euler
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Trying my hand atProject Euler as I stumble along learning Rust. I shall only add thesolutions to the first hundred problems here with the intention being to showcase whatever useful data structures Ibuild along the way. (This is permitted according to the Project Euler guidelines.) Further, I shall restrict myself tothe standard library.
To solve, say, problem 16, enter the following command.
cargo r 16
Run it without arguments to sequentially solve all problems for which I have written solutions.
cargo r
Most solutions are rather concise; the heavy lifting is done in theutils
module. This highlights the intent of thecode by hiding confounding implementation details. Items of particular note therein are the following.
is_prime
: fast prime checker which combines trial division and the Miller-Rabin algorithm.pow
: modular exponentiation calculator, emulating thepow
function of Python.Long
: arbitrary-precision integer type with support for addition and multiplication.Long::factorial
: factorial calculator.Long::pow
: exponentiation calculator.
SieveOfAtkin
: fast prime-generating sieve.The sieve of Atkin is faster than the sieve of Eratosthenes.SieveOfAtkin::is_prime
: prime checker for numbers the sieve is generated up to.SieveOfAtkin::iter
: iterator over generated primes.
Polygonal
: figurate (triangle, quadrilateral, pentagon, hexagon, …) number generator. Uses only additions andsubtractions.Polygonal::invert
: figurate number checker.
PythagoreanTriplets
: Pythagorean triplets generator.
No part of the code in this repository has been written by or in consultation with artificial intelligence chatbotssuch as (but not limited to) Bard and ChatGPT.
About
My solutions to some Project Euler problems. Emphasis on elegance (where possible) and performance.