Skip to content

Instantly share code, notes, and snippets.

@RandyMcMillan
Forked from rust-play/playground.rs
Last active January 10, 2025 16:28
Show Gist options
  • Save RandyMcMillan/44e636b2a749e49b4902977df88dcd18 to your computer and use it in GitHub Desktop.
Save RandyMcMillan/44e636b2a749e49b4902977df88dcd18 to your computer and use it in GitHub Desktop.
bitcoin_supply.rs
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);
}
@RandyMcMillan
Copy link
Author

RandyMcMillan commented Jan 10, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment