Math machines is a small collection of mathematical sequences expressed in the form of methods to calculate the Nth number of a sequence.
use math_machines::{MMInt, Machine, lru_calculate, Fibonacci};
use rand;
let mut machine = Machine::new(Fibonacci{}, 128, 50);
for _ in 0..50 {
let n = rand::random::<MMInt>() % 50;
let r = lru_calculate(&mut machine, n).expect("Nth value of Fibonacci");
println!("fibonacci({n:02}): {:-10}", r);
}
- Fibonacci sequence
- Harmonic series
- Primes sequence
Machines that are defined in this project caches results at runtime using an implementation of LRU (least recently used) where, once a machine's internal cache has reached capacity, or the greatest age since usage has reach it's maximum, cached entries are dropped.