Thue-Morse: Difference between revisions
→{{header|F_Sharp|F#}}
Not a robot (talk | contribs) (Add PL/M) |
|||
(20 intermediate revisions by 11 users not shown) | |||
Line 15:
<syntaxhighlight lang="11l">F thue_morse_digits(digits)
R (0 .< digits).map(n ->
print(thue_morse_digits(20))</syntaxhighlight>
Line 180:
0110100110010110100101100110100110010110011010010110100110010110
</pre>
=={{header|APL}}==
<syntaxhighlight lang="apl">⍝ generate the first ⍵ elements of the Thue-Morse sequence
tm←{⍵⍴(⊢,~)⍣(⍵≤(⍴⊢))⊢,0}</syntaxhighlight>
{{out}}
<pre> tm 32
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 1 1 0 1 0 0 1</pre>
=={{header|AppleScript}}==
Line 480 ⟶ 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 875 ⟶ 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
<syntaxhighlight lang="elena">import extensions;
import system'text;
Line 886 ⟶ 926:
var sb1 := TextBuilder.load("0");
var sb2 := TextBuilder.load("1");
for(int i := 0
{
var tmp := sb1.Value;
Line 1,140 ⟶ 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,271 ⟶ 1,323:
=={{header|Fōrmulæ}}==
{{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,757 ⟶ 1,857:
0110100110010110...transmitted
</pre>
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro11"> .TITLE THUE
.MCALL .TTYOUT,.EXIT
THUE:: MOV #100,R3 ; 64 ITEMS
CLR R2
1$: JSR PC,SEQ ; GET THUE-MORSE SEQUENCE ITEM
ADD #60,R0 ; MAKE ASCII
.TTYOUT ; PRINT
INC R2
SOB R3,1$
.EXIT
; LET R0 = R2'TH ITEM IN THUE MORSE SEQUENCE
SEQ: CLR R0
MOV #20,R1
1$: ROR R0
XOR R2,R0
SOB R1,1$
BIC #^C1,R0
RTS PC
.END THUE</syntaxhighlight>
{{out}}
<pre>0110100110010110100101100110100110010110011010010110100110010110</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Line 1,762 ⟶ 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,364 ⟶ 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,439 ⟶ 2,607:
01101001100101101001011001101001
0110100110010110100101100110100110010110011010010110100110010110
</pre>
=={{header|RPL}}==
{{works with|HP|48G}}
We use here the bitwise negation method: it needs few words and is actually faster than the "fast" generation method, because RPL is better in list handling than in bitwise calculations.
≪ { 0 }
'''WHILE''' DUP2 SIZE > '''REPEAT'''
1 OVER - +
'''END'''
1 ROT SUB
≫ '<span style="color:blue">THUEM</span>' STO
20 <span style="color:blue">THUEM</span>
{{out}}
<pre>
1: { 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 1 }
</pre>
Line 2,657 ⟶ 2,841:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="
var sb0 = "0"
var sb1 = "1"
|