-
-
Save RandyMcMillan/44e636b2a749e49b4902977df88dcd18 to your computer and use it in GitHub Desktop.
bitcoin_supply.rs
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
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=44e636b2a749e49b4902977df88dcd18