diff --git a/README.rst b/README.rst index 45f250d3..19818acc 100644 --- a/README.rst +++ b/README.rst @@ -88,7 +88,7 @@ Olivia's Project Euler Solutions | | GraalPy 23.1+ |br| | | |CodeQL| |br| | | | Browser [#]_ | | |PythonLint| | +------------+----------------------------+--------+-------------------+ -| Rust | 1.69+ |br| | 35 | |Rust| |br| | +| Rust | 1.69+ |br| | 36 | |Rust| |br| | | | Browser [#]_ | | |Rs-Cov| |br| | | | | | |RustClippy| | +------------+----------------------------+--------+-------------------+ diff --git a/docs/index.rst b/docs/index.rst index a07480ed..073d31c1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -192,7 +192,7 @@ Problems Solved +-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`63` | | | | | |:py-d:`0063`| | +-----------+------------+------------+------------+------------+------------+------------+------------+ -|:prob:`67` | | | | | |:py-d:`0067`| | +|:prob:`67` | | | | | |:py-d:`0067`|:rs-d:`0067`| +-----------+------------+------------+------------+------------+------------+------------+------------+ |:prob:`69` | | | | | |:py-d:`0069`|:rs-d:`0069`| +-----------+------------+------------+------------+------------+------------+------------+------------+ diff --git a/docs/src/rust/p0059.rst b/docs/src/rust/p0059.rst new file mode 100644 index 00000000..6b3ab0f5 --- /dev/null +++ b/docs/src/rust/p0059.rst @@ -0,0 +1,20 @@ +Rust Implementation of Problem 59 +================================= + +View source code :source:`rust/src/p0059.rs` + +Includes +-------- + +- `utils <./lib/utils.html>`_ + +Problem Solution +---------------- + +.. rust:fn:: pub fn p0059::p0059() -> utils::Answer + +.. literalinclude:: ../../../rust/src/p0059.rs + :language: rust + :linenos: + +.. tags:: cryptography, binary-operator, xor, file-io diff --git a/docs/src/rust/p0067.rst b/docs/src/rust/p0067.rst new file mode 100644 index 00000000..f2cbd809 --- /dev/null +++ b/docs/src/rust/p0067.rst @@ -0,0 +1,21 @@ +Rust Implementation of Problem 67 +================================= + +View source code :source:`rust/src/p0067.rs` + +Includes +-------- + +- `triangles <./lib/triangles.html>`_ +- `utils <./lib/utils.html>`_ + +Problem Solution +---------------- + +.. rust:fn:: pub fn p0067::p0067() -> utils::Answer + +.. literalinclude:: ../../../rust/src/p0067.rs + :language: rust + :linenos: + +.. tags:: combinatorics, path-finding, file-io diff --git a/rust/README.rst b/rust/README.rst index a7a12c15..e75998d5 100644 --- a/rust/README.rst +++ b/rust/README.rst @@ -88,6 +88,7 @@ Problems Solved - ☒ `45 <./src/p0045.rs>`__ - ☒ `53 <./src/p0053.rs>`__ - ☒ `59 <./src/p0059.rs>`__ +- ☒ `67 <./src/p0067.rs>`__ - ☒ `69 <./src/p0069.rs>`__ - ☒ `76 <./src/p0076.rs>`__ - ☒ `77 <./src/p0077.rs>`__ diff --git a/rust/src/include/problems.rs b/rust/src/include/problems.rs index fffdea1e..c7069922 100644 --- a/rust/src/include/problems.rs +++ b/rust/src/include/problems.rs @@ -11,6 +11,7 @@ use crate::p0037::p0037; use crate::p0045::p0045; use crate::p0053::p0053; use crate::p0059::p0059; +use crate::p0067::p0067; use crate::p0069::p0069; use crate::p0076::p0076; use crate::p0077::p0077; @@ -54,6 +55,7 @@ pub fn get_problem<'b>(n: usize) -> Option> { 45 => Some(( &45, p0045, false)), 53 => Some(( &53, p0053, false)), 59 => Some(( &59, p0059, false)), + 67 => Some(( &67, p0067, false)), 69 => Some(( &69, p0069, false)), 76 => Some(( &76, p0076, false)), 77 => Some(( &77, p0077, false)), diff --git a/rust/src/lib.rs b/rust/src/lib.rs index a75b0adc..994c99b7 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -16,6 +16,7 @@ pub mod p0037; pub mod p0045; pub mod p0053; pub mod p0059; +pub mod p0067; pub mod p0069; pub mod p0076; pub mod p0077; diff --git a/rust/src/main.rs b/rust/src/main.rs index 276814d3..3a8f4d41 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -33,6 +33,7 @@ pub mod p0037; pub mod p0045; pub mod p0053; pub mod p0059; +pub mod p0067; pub mod p0069; pub mod p0076; pub mod p0077; @@ -85,6 +86,7 @@ seq!(N in 01..=20 { #[case::problem_45(45)] #[case::problem_53(53)] #[case::problem_59(59)] +#[case::problem_67(67)] #[case::problem_69(69)] #[case::problem_76(76)] #[case::problem_77(77)] diff --git a/rust/src/p0018.rs b/rust/src/p0018.rs index 948edcb6..6d6fb70a 100644 --- a/rust/src/p0018.rs +++ b/rust/src/p0018.rs @@ -1,5 +1,5 @@ /* -Project Euler Problem 18 +Project Euler Problem 67 Thinking from the bottom up got the answer @@ -8,38 +8,19 @@ Problem: By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. -.. code-block:: - - 3 - 7 4 - 2 4 6 - 8 5 9 3 +3 +7 4 +2 4 6 +8 5 9 3 That is, 3 + 7 + 4 + 9 = 23. -Find the maximum total from top to bottom of the triangle below: - -.. code-block:: - - 75 - 95 64 - 17 47 82 - 18 35 87 10 - 20 04 82 47 65 - 19 01 23 75 03 34 - 88 02 77 73 07 63 67 - 99 65 04 28 06 16 70 92 - 41 41 26 56 83 40 80 70 33 - 41 48 72 33 47 32 37 16 94 29 - 53 71 44 65 25 43 91 52 97 51 14 - 70 11 33 28 77 73 17 78 39 68 17 57 - 91 71 52 38 17 14 91 43 58 50 27 29 48 - 63 66 04 68 89 53 67 30 73 16 69 87 40 31 - 04 62 98 27 23 09 70 98 73 93 38 53 60 04 23 +Find the maximum total from top to bottom in triangle.txt (right click and 'Save Link/Target As...'), a 15K text file +containing a triangle with one-hundred rows. -NOTE: As there are only 16384 routes, it is possible to solve this problem by trying every route. However, Problem 67, -is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a -clever method! ;o) +NOTE: This is a much more difficult version of Problem 18. It is not possible to try every route to solve this problem, +as there are 2^99 altogether! If you could check one trillion (10^12) routes every second it would take over twenty +billion years to check them all. There is an efficient algorithm to solve it. ;o) */ use crate::include::triangles::reduce_triangle; use crate::include::utils::Answer; diff --git a/rust/src/p0067.rs b/rust/src/p0067.rs new file mode 100644 index 00000000..c31f20a1 --- /dev/null +++ b/rust/src/p0067.rs @@ -0,0 +1,35 @@ +/* +Project Euler Problem 67 + +Thinking from the bottom up got the answer + +Problem: + +By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top +to bottom is 23. + +3 +7 4 +2 4 6 +8 5 9 3 + +That is, 3 + 7 + 4 + 9 = 23. + +Find the maximum total from top to bottom in triangle.txt (right click and 'Save Link/Target As...'), a 15K text file +containing a triangle with one-hundred rows. + +NOTE: This is a much more difficult version of Problem 18. It is not possible to try every route to solve this problem, +as there are 2^99 altogether! If you could check one trillion (10^12) routes every second it would take over twenty +billion years to check them all. There is an efficient algorithm to solve it. ;o) +*/ +use crate::include::triangles::reduce_triangle; +use crate::include::utils::{get_data_file,Answer}; + + +pub fn p0018() -> Answer { + let rows: Vec> = vec![]; + for line in get_data_file("p0067_triangle.txt").trim().lines() { + rows.push(line.split(' ').map(|x| x.parse::()).collect::>()); + } + return Answer::Int(reduce_triangle(rows).into()); +}