Skip to content

Commit

Permalink
add forgotten file, fix table
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jul 14, 2024
1 parent 328dafe commit a55966b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ LivInTheLookingGlass’s Project Euler solutions
+-------------------------------------------+---------------+
| Code Coverage (in progress) | |Coverage| |
+-------------------------------------------+---------------+
y| Code Scanning | |CodeQL| |br| |
| Code Scanning | |CodeQL| |br| |
| | |ESLint| |br| |
| | |RustClippy| |
+-------------------------------------------+---------------+
Expand Down
32 changes: 32 additions & 0 deletions rust/src/p0004.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Project Euler Problem 4
I couldn't figure out how to do this as efficiently as I would have liked. I am
SURE that there is a better way to check if a number is a palindrome, but I
could not think of one.
Problem:
A palindromic number reads the same both ways. The largest palindrome made from
the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
*/
use itertools::Itertools;

fn is_palindrome(x: u64) -> bool {
let s = x.to_string();
return s == s.chars().rev().collect::<String>();
}

pub fn p0004() -> u64 {
let mut answer: u64 = 0;
for v in (100..1000).combinations(2) {
let p = v.into_iter().product();
if is_palindrome(p) && p > answer {
answer = p;
}
}
return answer;
}

0 comments on commit a55966b

Please sign in to comment.