Trying my hand at Project Euler as I stumble along learning Rust. I shall only add the solutions to the first hundred problems here with the intention being to showcase whatever useful data structures I build along the way. (This is permitted according to the Project Euler guidelines.) Further, I shall restrict myself to the 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 the utils
module. This highlights the intent of the
code 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 and subtractions.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 chatbots such as (but not limited to) Bard and ChatGPT.