add frequency summary and bitstream output option

This commit is contained in:
mehbark 2025-12-25 00:28:51 -05:00
parent 43057a55d6
commit a911b74855
Signed by: mbk
GPG key ID: E333EC1335FFCCDB

View file

@ -8,16 +8,29 @@ fn main() {
.parse() .parse()
.unwrap(); .unwrap();
let bitstream = env::args()
.nth(2)
.is_some_and(|arg| arg.to_ascii_lowercase().contains("bitstream"));
let p = 2 * s + 1; let p = 2 * s + 1;
let mut qr = vec![false; p]; let mut qr = vec![false; p];
for n in 1..p { for n in 1..p {
qr[(n * n) % p] = true; qr[(n * n) % p] = true;
} }
for is_qr in qr { for &is_qr in &qr {
let color_code: u8 = if is_qr { 255 } else { 232 }; let color_code: u8 = if is_qr { 255 } else { 232 };
print!("\x1b[48;5;{color_code}m "); if bitstream {
print!("{}", u8::from(is_qr));
} else {
print!("\x1b[48;5;{color_code}m ");
}
}
if !bitstream {
println!("\x1b[0m");
} }
print!("\x1b[0m"); #[allow(clippy::cast_precision_loss)]
let freq = qr.iter().skip(1).filter(|is_qr| **is_qr).count() as f64 / (p as f64 - 1.);
eprintln!("QR frequency: {:.2}%", freq * 100.);
} }