Thue-Morse: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: generator)
Line 1,360: Line 1,360:


=={{header|jq}}==
=={{header|jq}}==
'''Adapted from [[#Wren]]'''
{{works with|jq}}
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
'''Works with gojq, the Go implementation of jq'''


`thueMorse` as defined here generates an indefinitely long stream of the Thue-Morse integers:
<lang jq>def thueMorse:
<lang>def thueMorse:
reduce range(0; .) as $_ (
0,
{sb0: "0", sb1: "1" };
{sb0: (.sb0 + .sb1), sb1: (.sb1 + .sb0)} )
({sb0: "0", sb1: "1", n:1 }
| .sb0 ;
| while( true;
{n: (.sb0|length),
sb0: (.sb0 + .sb1),
range(0;7)
sb1: (.sb1 + .sb0)} )
| "\(.) : \(thueMorse)"</lang>
| .sb0[.n:]
| explode[]
| . - 48);</lang>
'''Example:'''
<lang>[limit(100;thueMorse)] | join("")</lang>
{{out}}
{{out}}
</pre> 0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110
As for [[#wren]].
</pre>

=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}