counts.rs

1.1 kB · rust · 47 lines

1use crate::tile::line_reducible;2use num_bigint::BigUint;34pub fn total(bits: usize) -> BigUint {5    (BigUint::from(1u32) << bits) - BigUint::from(1u32)6}78pub fn tile_total(side: usize) -> BigUint {9    total(side * side)10}1112pub fn line_total(side: usize) -> BigUint {13    total(side)14}1516pub fn irreducibles(totals: &[BigUint]) -> Vec<BigUint> {17    let mut out: Vec<BigUint> = Vec::new();18    for k in 0..totals.len() {19        let mut value = totals[k].clone();20        for j in 0..k {21            value -= &out[j] * &totals[k - 1 - j];22        }23        out.push(value);24    }25    out26}2728pub fn reducible_at(prime: usize, power: usize, plane: bool) -> BigUint {29    let totals: Vec<BigUint> = (1..=power)30        .map(|k| {31            let side = prime.pow(k as u32);32            if plane {33                tile_total(side)34            } else {35                line_total(side)36            }37        })38        .collect();39    let irr = irreducibles(&totals);40    &totals[power - 1] - &irr[power - 1]41}4243pub fn line_brute(side: usize) -> usize {44    (1u128..1u128 << side)45        .filter(|mask| line_reducible(*mask, side))46        .count()47}