Skip to content

Instantly share code, notes, and snippets.

@SekiT
Created March 3, 2023 01:30
Show Gist options
  • Save SekiT/20c2d4ebced3ed756f43403294a9798f to your computer and use it in GitHub Desktop.
Save SekiT/20c2d4ebced3ed756f43403294a9798f to your computer and use it in GitHub Desktop.
Cyclic Tag System implementation
function*cts(S,d){for(i=0;d;d=d.slice(1)+['',S[i++%S.length]][d[0]])yield d}
// Example usage
let j=0; for(v of cts(["01", "10"], "11")){ console.log(v); if(++j>=10) break }
@SekiT
Copy link
Author

SekiT commented Mar 3, 2023

Elixir version (without handling empty string):

cts=&Stream.unfold{&1,&2},fn{d=<<h>><>t,[s|r]}->{d,{t<>"#{%{?1=>s}[h]}",r++[s]}}end

"11" |> cts.(["01", "10"]) |> Stream.take(10) |> Enum.each(&IO.puts/1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment