-
-
Save rust-play/0bc726f276943b5fb5f7fa8b821e1765 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
fn main() { | |
let mut sum: u64 = 0; | |
for x in 0..=32 { | |
// Calculate the term inside the summation | |
let term: f64 = (50.0 * 1e8) / (2.0_f64.powi(x as i32)); | |
println!("{} {}", x, term.to_string()); | |
// Take the floor of the result | |
let floor_term: u64 = term.floor() as u64; | |
// Add it to the sum | |
sum += floor_term; | |
} | |
// Multiply by 210000 as per the formula | |
let result = 210000 * sum; | |
assert_eq!(result, 2099999997690000); | |
println!("{}", result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment