Thue-Morse: Difference between revisions

(add RPL)
 
(16 intermediate revisions by 10 users not shown)
Line 15:
 
<syntaxhighlight lang="11l">F thue_morse_digits(digits)
R (0 .< digits).map(n -> binbits:popcount(n).count(‘1’) % 2)
 
print(thue_morse_digits(20))</syntaxhighlight>
Line 487:
{{out}}
<pre>0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110</pre>
 
=={{header|Binary Lambda Calculus}}==
 
The (infinite) Thue-Morse sequence is output by the 115 bit BLC program
 
<pre>0001000110100001010100011010000000000101101110000101100000010111111101011001111001111110111110000011001011010000010</pre>
 
as documented in https://github.com/tromp/AIT/blob/master/characteristic_sequences/thue-morse.lam
 
Output:
 
<pre>01101001100101101001011001101001100101100110100101101001100101101001011001101001011010011001011001101001100101101001011001101001100101100110100101101001100101100110100110010110100101100110100101101001...</pre>
 
=={{header|BQN}}==
Line 882 ⟶ 894:
{{out}}
<pre>0110100110010110100101100110100110010110011010010110100110010110</pre>
 
=={{header|EasyLang}}==
{{trans|BASIC256}}
<syntaxhighlight>
func$ tmorse s$ .
for i to len s$
if substr s$ i 1 = "1"
k$ &= "0"
else
k$ &= "1"
.
.
return s$ & k$
.
tm$ = "0"
print tm$
for j to 7
tm$ = tmorse tm$
print tm$
.
</syntaxhighlight>
 
=={{header|Elena}}==
{{trans|C#}}
ELENA 46.x :
<syntaxhighlight lang="elena">import extensions;
import system'text;
Line 893 ⟶ 926:
var sb1 := TextBuilder.load("0");
var sb2 := TextBuilder.load("1");
for(int i := 0,; i < steps,; i += 1)
{
var tmp := sb1.Value;
Line 1,147 ⟶ 1,180:
| 0110100110010110100101100110100110010110011010010110100110010110
|}
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Thue-Morse. Nigel Galloway: April 16th., 2024
let rec fG n g=match n with 0->g |1->g+1 |n ->fG(n/2)(g+n&&&1)
let thueMorse=Seq.initInfinite(fun n->(fG n 0)%2)
thueMorse|>Seq.take 25|>Seq.iter(printf "%d "); printfn ""
</syntaxhighlight>
{{out}}
<pre>
0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0
</pre>
 
=={{header|Factor}}==
Line 1,279 ⟶ 1,324:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Thue-Morse}}
 
=== Solution 1 ===
 
[[File:Fōrmulæ - Thue–Morse sequence 01.png]]
 
[[File:Fōrmulæ - Thue–Morse sequence 11.png]]
 
=== Solution 2 ===
 
[[File:Fōrmulæ - Thue–Morse sequence 02.png]]
 
[[File:Fōrmulæ - Thue–Morse sequence 11.png]]
 
=== Solution 3 ===
 
[[File:Fōrmulæ - Thue–Morse sequence 03.png]]
 
[[File:Fōrmulæ - Thue–Morse sequence 11.png]]
 
=== Solution 4 ===
 
Notice that this solution generates a string.
 
[[File:Fōrmulæ - Thue–Morse sequence 04.png]]
 
[[File:Fōrmulæ - Thue–Morse sequence 12.png]]
 
=== Solution 5 ===
 
Notice that this solution generates a string.
 
[[File:Fōrmulæ - Thue–Morse sequence 05.png]]
 
[[File:Fōrmulæ - Thue–Morse sequence 12.png]]
 
=== Solution 6 ===
 
Notice that this solution generates a string.
 
[[File:Fōrmulæ - Thue–Morse sequence 06.png]]
 
[[File:Fōrmulæ - Thue–Morse sequence 12.png]]
 
=== Solution 7. L-system ===
 
There are generic functions written in Fōrmulæ to compute an L-system in the page [[L-system#Fōrmulæ | L-system]].
 
The program that creates a Hilbert curve is:
 
[[File:Fōrmulæ - L-system - Thue-Morse 01.png]]
 
[[File:Fōrmulæ - Thue–Morse sequence 12.png]]
 
=={{header|Go}}==
Line 1,789 ⟶ 1,886:
{{out}}
<pre>{1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0}</pre>
 
=={{header|MATLAB}}==
===MATLAB: By counting set ones in binary representation===
<syntaxhighlight lang="MATLAB">
tmSequence = thue_morse_digits(20);
disp(tmSequence);
 
function tmSequence = thue_morse_digits(n)
tmSequence = zeros(1, n);
for i = 0:(n-1)
binStr = dec2bin(i);
numOnes = sum(binStr == '1');
tmSequence(i+1) = mod(numOnes, 2);
end
end
</syntaxhighlight>
{{out}}
<pre>
0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1
</pre>
 
 
=={{header|Miranda}}==
Line 2,391 ⟶ 2,509:
01101001100101101001011001101001100101100110100101101001100101101001011001101001011010011001011001101001100101101001011001101001
^C</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <ThueMorse 7>>
};
 
ThueMorse {
0 e.X = e.X;
s.N e.X = <ThueMorse <- s.N 1> <ThueMorseStep e.X>>;
};
 
ThueMorseStep {
= '0';
e.X = e.X <Invert e.X>;
};
 
Invert {
= ;
'0' e.X = '1' <Invert e.X>;
'1' e.X = '0' <Invert e.X>;
};</syntaxhighlight>
{{out}}
<pre>0110100110010110100101100110100110010110011010010110100110010110</pre>
 
=={{header|REXX}}==
Line 2,700 ⟶ 2,841:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">var thueMorse = Fn.new { |n|
var sb0 = "0"
var sb1 = "1"
2,171

edits