Skip to content

Commit

Permalink
Fix typo in main, p0007, solve p0010
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jul 14, 2024
1 parent 26ed5d7 commit 452b316
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LivInTheLookingGlass’s Project Euler solutions
| | Pypy 3.6+ |br| | | |
| | GraalPy 23.1+ | | |
+------------+---------------------+--------------+---------------+
| Rust | 1.69+ | 4 / |total| | |Rust| |
| Rust | 1.69+ | 5 / |total| | |Rust| |
+------------+---------------------+--------------+---------------+
| Documentation (in progress) | |Pages| |
+-------------------------------------------------+---------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ This project is divided into several Makefiles, connected by a root Makefile whi
+-----------+------+------+------+------+------+
|:prob:`9` | |d| | | | |d| | |
+-----------+------+------+------+------+------+
|:prob:`10` | |d| | | | |d| | |
|:prob:`10` | |d| | | | |d| | |d| |
+-----------+------+------+------+------+------+
|:prob:`11` | |d| | | | |d| | |
+-----------+------+------+------+------+------+
Expand Down
18 changes: 18 additions & 0 deletions docs/rust/p0010.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Rust Implementation of Problem 10
=================================

View source code `here on GitHub! <https://github.com/LivInTheLookingGlass/Euler/blob/master/rust/src/p0010.rs>`_

Includes
--------

- `primes <./primes.html>`_

Problem Solution
----------------

.. rust:fn:: p0010::p0010() -> u64
.. literalinclude:: ../../rust/src/p0010.rs
:language: rust
:linenos:
6 changes: 4 additions & 2 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ seq!(N in 0001..=0003 {
mod p~N;
});
mod p0007;
mod p0010;
mod primes;

type ProblemType = fn() -> u64;
type ProblemRef<'a> = (&'a str, ProblemType, u64);
const ANSWERS: [ProblemRef; 4] = [
const ANSWERS: [ProblemRef; 5] = [
("p0001", p0001::p0001, 233168),
("p0002", p0002::p0002, 4613732),
("p0003", p0003::p0003, 6857),
("p0007", p0007::p0007, 104743),
("p0010", p0010::p0010, 142913828922),
];

fn main() {
Expand All @@ -36,7 +38,7 @@ fn main() {
}

#[cfg(test)]
seq!(N in 0..3 {
seq!(N in 0..=4 {
#[rstest]
#[timeout(Duration::new(60, 0))]
#(
Expand Down
7 changes: 1 addition & 6 deletions rust/src/p0007.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,5 @@ What is the 10 001st prime number?
use crate::primes::primes;

pub fn p0007() -> u64 {
for (i, p) in primes().enumerate() {
if i == 1001 {
return p;
}
}
return 0;
return primes().take(10001).last().unwrap();
}
5 changes: 5 additions & 0 deletions rust/src/p0010.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::primes::primes;

pub fn p0010() -> u64 {
return primes::<u64>().take_while(|&p| p < 2000000).sum();
}

0 comments on commit 452b316

Please sign in to comment.