~janbaudisch/euler-rs

3ea08e0b6352b89b2b936c43926012d99147811e — Jan Baudisch 5 years ago 8083510
add: problem 36
4 files changed, 38 insertions(+), 1 deletions(-)

M Cargo.lock
M Cargo.toml
A problem_036/Cargo.toml
A problem_036/src/main.rs
M Cargo.lock => Cargo.lock +7 -0
@@ 62,3 62,10 @@ dependencies = [
 "common 0.1.0",
]

[[package]]
name = "problem_036"
version = "0.1.0"
dependencies = [
 "common 0.1.0",
]


M Cargo.toml => Cargo.toml +2 -1
@@ 9,7 9,8 @@ members = [
    "problem_007",
    "problem_010",
    "problem_019",
    "problem_035"
    "problem_035",
    "problem_036"
]

[profile.release]

A problem_036/Cargo.toml => problem_036/Cargo.toml +8 -0
@@ 0,0 1,8 @@
[package]
name = "problem_036"
version = "0.1.0"
authors = ["Jan Baudisch <dev@baudisch.xyz>"]
edition = "2018"

[dependencies]
common = { path = "../common" }

A problem_036/src/main.rs => problem_036/src/main.rs +21 -0
@@ 0,0 1,21 @@
use common::format::ToBinary;
use common::input;
use common::math::IsPalindrome;

fn main() {
    println!("[INPUT] calculate until:");
    let limit = u64::from_str_radix(&input::read_line(), 10).expect("Could not parse input!");

    let mut sum = 0;

    for n in 0..limit {
        if n.is_palindrome() && n.to_binary().is_palindrome() {
            sum += n;
        }
    }

    println!(
        "[SOLUTION] sum of palindromic numbers in base 10 and 2 under {}: {}",
        limit, sum
    );
}