Copyright | (c) Eric Bailey 2025 |
---|---|
License | MIT |
Maintainer | eric@ericb.me |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Data.Rhythm.Binary.RuskeySavageWang
Description
Binary necklaces, internally encoded as numbers.
References
- Frank Ruskey, Carla Savage, Terry Min Yih Wang, Generating necklaces, Journal of Algorithms, Volume 13, Issue 3, 1992, Pages 414-430, ISSN 0196-6774, https://doi.org/10.1016/0196-6774(92)90047-G.
Documentation
necklaces :: Int -> [[Int]] Source #
All binary necklaces of a given length.
>>>
necklaces 4
[[1,1,1,1],[1,1,1,0],[1,1,0,0],[1,0,1,0],[1,0,0,0],[0,0,0,0]]
necklaces' :: (Integral a, Bits a) => Int -> Tree a Source #
All binary necklaces of a given length, encoded as numbers.
\[ \begin{align*} \sigma(x_1 ... x_n) &= x_2 ... x_n x_1 \\ \tau(x_1 ... x_{n-1}) &= x_1 ... x_{n-1}\overline{x_n} \end{align*} \]
Generate the tree of binary necklaces of length \(n\), starting with \(x = 0^n\) as root, where children of \(x\) are the necklaces of the form \(\tau\sigma^j(x)\) for \(1 \le j \le n -1\).
>>>
flatten (necklaces' 4)
[0,1,3,7,15,5]