use std::collections::HashMap;
fn accumulate(n: u32) -> u64 {
let mut total: u64 = 0;
for i in 1..=n {
total += i as u64;
}
total
}
fn describe(label: &str, value: u64) -> String {
let kind = classify(value);
let formatted = format!("{label} = {value} ({kind})");
formatted
}
fn classify(value: u64) -> &'static str {
if value % 2 == 0 {
"even"
} else {
"odd"
}
}
#[derive(Debug)]
#[allow(dead_code)]
struct Point {
x: i32,
y: i32,
label: String,
}
fn inspect_heap(sum: u64) -> usize {
let text: String = format!("sum is {sum}");
let numbers: Vec<u64> = (1..=sum).collect();
let point = Point {
x: 3,
y: 7,
label: String::from("origin-ish"),
};
let mut index: HashMap<String, u64> = HashMap::new();
index.insert("answer".to_string(), 42);
index.insert("sum".to_string(), sum);
numbers.len() + index.len() + point.x as usize + text.len()
}
fn main() {
let n: u32 = 10;
let sum = accumulate(n);
let report = describe("sum(1..=10)", sum);
let total = inspect_heap(sum);
println!("{report}; total={total}");
std::process::exit(0);
}