Jump to content

Thue-Morse: Difference between revisions

Add MATLAB implementation
(Add MATLAB implementation)
Line 1,831:
{{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}}==
338

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.