~janbaudisch/euler-rs

2ff36e9e8f0ba7a994fda3dc78b25f034b345587 — Jan Baudisch 5 years ago 97ae3a0
add: problem 9
4 files changed, 37 insertions(+), 0 deletions(-)

M Cargo.lock
M Cargo.toml
A problem_009/Cargo.toml
A problem_009/src/main.rs
M Cargo.lock => Cargo.lock +7 -0
@@ 45,6 45,13 @@ dependencies = [
]

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

[[package]]
name = "problem_010"
version = "0.1.0"
dependencies = [

M Cargo.toml => Cargo.toml +1 -0
@@ 7,6 7,7 @@ members = [
    "problem_005",
    "problem_006",
    "problem_007",
    "problem_009",
    "problem_010",
    "problem_019",
    "problem_035",

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

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

A problem_009/src/main.rs => problem_009/src/main.rs +21 -0
@@ 0,0 1,21 @@
use common::input;

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

    let mut product = 0;

    'outer: for a in 1..limit {
        for b in 1..limit {
            for c in 1..limit {
                if a + b + c == limit && a.pow(2) + b.pow(2) == c.pow(2) {
                    product = a * b * c;
                    break 'outer;
                }
            }
        }
    }

    println!("[SOLUTION] a * b * c = {}", product);
}