Created
May 3, 2017 08:18
-
-
Save ranjanprj/9eb778ae874d389527545592da32f668 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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. | |
*/ | |
fn reverse_num(num : u64 ) -> u64 { | |
let mut reverse =0; | |
let mut n = num; | |
while n != 0 { | |
reverse = reverse * 10; | |
reverse = reverse + n % 10; | |
n = n / 10; | |
} | |
reverse | |
} | |
fn is_palindrome(num : u64) -> bool{ | |
let rev_num = reverse_num(num); | |
if rev_num == num { | |
return true; | |
} | |
false | |
} | |
fn main(){ | |
let mut largest_palindrome = 0; | |
for i in 1..999 { | |
for j in 1..999{ | |
let n = i*j; | |
if n == 906609{ | |
println!("yay"); | |
} | |
if is_palindrome(n) && n > largest_palindrome{ | |
largest_palindrome = n; | |
} | |
} | |
} | |
println!("largest 3 digit palindrone {}",largest_palindrome); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment