paper-component-exponent-of-kronecker-words.rs

1.9 kB · rust · 63 lines

1use mrlycore::errors::Result;2use mrlyfig::{ink, save, Board, Grid};3use mrlymath::bang::{word, MagicLayer};4use mrlymath::name::Bang;56const CODES: usize = 15;7const LENGTH: usize = 32;8const SLACK: f64 = 0.25;910fn alternating(a: u128, b: u128) -> Vec<MagicLayer> {11    (0..LENGTH)12        .map(|place| {13            let code = if place % 2 == 0 { a } else { b };14            MagicLayer::new(Bang::new(code, 2, 2), 2)15        })16        .collect()17}1819fn verdict(a: u128, b: u128) -> Result<(bool, bool)> {20    let letters = alternating(a, b);21    let rates = word::rates(&letters)?;22    let (component, fill) = rates[rates.len() - 1];23    let constant = word::constant_functional(&letters)?;24    Ok((25        (component - fill).abs() < SLACK,26        (component - constant).abs() < SLACK,27    ))28}2930fn main() -> Result<()> {31    let mut board = Board::square();32    let grid = Grid::new(board.frame(0.08), CODES, CODES, 0.12);33    let mut alphabets = 0usize;34    let mut ceiling = 0usize;35    let mut exact = 0usize;36    for row in 0..CODES {37        for col in (row + 1)..CODES {38            let (meets, constant) = verdict(row as u128 + 1, col as u128 + 1)?;39            alphabets += 1;40            let (x, y, w, h) = grid.cell(col, row);41            if meets {42                ceiling += 1;43                board.rect(x, y, w, h, ink::green());44            } else {45                board.rect(x, y, w, h, ink::orange());46            }47            if constant {48                exact += 1;49                let pip = w * 0.34;50                board.rect(51                    x + (w - pip) / 2.0,52                    y + (h - pip) / 2.0,53                    pip,54                    pip,55                    ink::yellow(),56                );57            }58        }59    }60    assert_eq!((alphabets, ceiling, exact), (105, 89, 27));61    save("paper-component-exponent-of-kronecker-words", &board)?;62    Ok(())63}