Created
April 29, 2020 21:26
-
-
Save gavinsykes/ff1738f6a300f2c23c8a2848cf3f8a86 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
use std::env; | |
fn main() { | |
let args: Vec<String> = env::args().collect(); | |
let val: i32 = args[0].parse().unwrap(); | |
println!("Answer: {}",euler_1(val)); | |
} | |
fn euler_1(x: i32) -> i32 { | |
let mut result: i32 = 0; | |
let x = x/3; | |
let y = x/5; | |
let mut i = 1; | |
while i < x { | |
result += 3*i; | |
i += 1; | |
} | |
i = 1; | |
while i < y { | |
if 5*i % 3 != 0 { | |
result += 5*i; | |
i += 1; | |
} | |
} | |
result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment