Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created April 29, 2020 21:26
Show Gist options
  • Save gavinsykes/ff1738f6a300f2c23c8a2848cf3f8a86 to your computer and use it in GitHub Desktop.
Save gavinsykes/ff1738f6a300f2c23c8a2848cf3f8a86 to your computer and use it in GitHub Desktop.
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