Thue-Morse: Difference between revisions
Content added Content deleted
(→{{header|SQL}}: Added zkl) |
(→{{header|Perl 6}}: Added Perl 6 solution) |
||
Line 4: | Line 4: | ||
<lang AWK>BEGIN{print x="0"} |
<lang AWK>BEGIN{print x="0"} |
||
{gsub(/./," &",x);gsub(/ 0/,"01",x);gsub(/ 1/,"10",x);print x}</lang> |
{gsub(/./," &",x);gsub(/ 0/,"01",x);gsub(/ 1/,"10",x);print x}</lang> |
||
=={{header|Perl 6}}== |
|||
<lang perl6>my @tm := 0, -> *@s { @s.map({ + not $_ }) } ... *; |
|||
say @tm[^64].join;</lang> |
|||
{{out}} |
|||
<pre>0110100110010110100101100110100110010110011010010110100110010110</pre> |
|||
=={{header|SQL}}== |
=={{header|SQL}}== |
Revision as of 13:54, 20 September 2015
Thue-Morse is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Make Thue-Morse sequence.
AWK
<lang AWK>BEGIN{print x="0"} {gsub(/./," &",x);gsub(/ 0/,"01",x);gsub(/ 1/,"10",x);print x}</lang>
Perl 6
<lang perl6>my @tm := 0, -> *@s { @s.map({ + not $_ }) } ... *;
say @tm[^64].join;</lang>
- Output:
0110100110010110100101100110100110010110011010010110100110010110
SQL
This example is using SQLite. <lang SQL>with recursive a(a) as (select '0' union all select replace(replace(hex(a),30,'01'),31,'10') from a) select * from a;</lang>
zkl
<lang zkl>fcn next(str){ str.pump(str,fcn(c){ (0x61 - c.toAsc()).toChar() }) }</lang> <lang zkl>str:="0"; do(7){ str.println(); str=next(str) }</lang>
- Output:
0 01 0110 01101001 0110100110010110 01101001100101101001011001101001 0110100110010110100101100110100110010110011010010110100110010110