Skip to content

Instantly share code, notes, and snippets.

@anka-213
Forked from anonymous/playground.rs
Created April 15, 2016 18:54
Show Gist options
  • Save anka-213/c8418e18a8e465b8a483f658d8245799 to your computer and use it in GitHub Desktop.
Save anka-213/c8418e18a8e465b8a483f658d8245799 to your computer and use it in GitHub Desktop.
Project Euler Problem 36: Double-base palindromes
// Project Euler Problem 36: Double-base palindromes
fn binary(n: i32) -> String {
format!("{:b}", n)
}
fn decimal(n: i32) -> String {
n.to_string()
}
fn is_palindrome(s: String) -> bool {
let s1 = s.into_bytes();
let mut s2 = s1.clone();
s2.reverse();
s1 == s2
}
fn main() {
let mut sum = 0;
for n in 1..1000000 {
if is_palindrome(binary(n)) && is_palindrome(decimal(n)) {
//println!("{:b}, {}", n, n);
sum += n
}
}
println!("{}", sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment