add frequency summary and bitstream output option
This commit is contained in:
parent
43057a55d6
commit
a911b74855
1 changed files with 16 additions and 3 deletions
19
src/main.rs
19
src/main.rs
|
|
@ -8,16 +8,29 @@ fn main() {
|
|||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let bitstream = env::args()
|
||||
.nth(2)
|
||||
.is_some_and(|arg| arg.to_ascii_lowercase().contains("bitstream"));
|
||||
|
||||
let p = 2 * s + 1;
|
||||
let mut qr = vec![false; p];
|
||||
for n in 1..p {
|
||||
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 };
|
||||
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.);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue