diff --git a/docs/rust/p0003.rst b/docs/rust/p0003.rst new file mode 100644 index 00000000..8ba385c9 --- /dev/null +++ b/docs/rust/p0003.rst @@ -0,0 +1,18 @@ +Rust Implementation of Problem 3 +================================ + +View source code `here on GitHub! `_ + +Includes +-------- + +- `primes <./primes.html>`_ + +Problem Solution +---------------- + +.. rust:fn:: p0003::p0003() -> u64 + +.. literalinclude:: ../../rust/src/p0003.rs + :language: rust + :linenos: diff --git a/rust/src/main.rs b/rust/src/main.rs index 15222fba..44945f2f 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -9,17 +9,17 @@ use rstest::rstest; #[cfg(test)] use itertools::Itertools; -seq!(N in 0001..=0002 { +seq!(N in 0001..=0003 { mod p~N; }); mod primes; type ProblemType = fn() -> u64; type ProblemRef<'a> = (&'a str, ProblemType, u64); -const ANSWERS: [ProblemRef; 2] = [ +const ANSWERS: [ProblemRef; 3] = [ ("p0001", p0001::p0001, 233168), ("p0002", p0002::p0002, 4613732), -// ("p0003", p0003::p0003, 6857), + ("p0003", p0003::p0003, 6857), ]; fn main() { diff --git a/rust/src/p0003.rs b/rust/src/p0003.rs new file mode 100644 index 00000000..364c1e89 --- /dev/null +++ b/rust/src/p0003.rs @@ -0,0 +1,16 @@ +/* +Project Euler Problem 3 + +This problem was fun, because it let me learn how to make Iterators in rust + +Problem: + +The prime factors of 13195 are 5, 7, 13 and 29. + +What is the largest prime factor of the number 600851475143 ? +*/ +mod primes; + +pub fn p0003() -> u64 { + return primes::prime_factors(600851475143).max(); +}