Expand description
This crate implements an iterator returning the tuples (kn, dn), where kn is the n
th 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]
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:
println!("{:?}", Kolakoski::new(1_000_000_000).take(100).collect::<Vec<_>>());
Structs§
- Kolakoski
- The main iterator structure.
- Kolakoski
Data - Use this if you want to efficiently create several iterators starting at different values of
n
, or if you want more control over the initialisation of the iterator.