Rust Implementation of Problem 36

View source code here on GitHub!

Includes

Problem Solution

pub fn problems::p0036::p0036() -> utils::Answer
 1/*
 2Project Euler Problem 36
 3
 4Rust implementing a `reverse_bits()` function made this much more pleasant than expected
 5
 6Problem:
 7
 8The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
 9
10Find the sum of all numbers, less than one million, which are palindromic in
11base 10 and base 2.
12
13(Please note that the palindromic number, in either base, may not include
14leading zeros.)
15*/
16use crate::include::utils::{is_palindrome,Answer};
17
18pub fn p0036() -> Answer {
19    let mut answer: u64 = 0;
20    for x in 1..1000000u64 {
21        if is_palindrome(format!("{x:b}")) && is_palindrome(x) {
22            answer += x;
23        }
24    }
25    return Answer::Int(answer.into());
26}

Tags: palindrome, number-base