kolakoski_algorithms 0.1.0

Efficient algorithms for the Kolakoski sequence
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented1 out of 6 items with examples
  • Size
  • Source code size: 19.58 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.41 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • colt-browning/kolakoski
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • colt-browning

This crate implements an iterator returning the tuples (kn, dn), where kn is the nth term of the Kolakoski sequence and dn = ∑i in 1..=n (−1)ki is the “Kolakoski discrepancy function”.

use kolakoski_algorithms::Kolakoski;

println!("{:?}", Kolakoski::default().take(20).map(|(k, _)| k).collect::<Vec<_>>());
// [1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1]
# assert_eq!(&[1, 2, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 1][..], &Kolakoski::default().take(20).map(|(k, _)| k).collect::<Vec<_>>());

If you are interested in analysing the behaviour of the sequence for certain large values of the argument, you can avoid generating all preceding terms:

# use kolakoski_algorithms::Kolakoski;
println!("{:?}", Kolakoski::new(1_000_000_000).take(100).collect::<Vec<_>>());