Thue-Morse: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|JavaScript}}: ES6) |
||
Line 299: | Line 299: | ||
}</lang> |
}</lang> |
||
<pre>0110100110010110100101100110100110010110011010010110100110010110</pre> |
<pre>0110100110010110100101100110100110010110011010010110100110010110</pre> |
||
=={{header|JavaScript}}== |
|||
===ES6=== |
|||
<lang JavaScript>(() => { |
|||
'use strict'; |
|||
// THUE MORSE |
|||
// thueMorse :: Int -> String |
|||
let thueMorse = nCycles => range(1, Math.abs(nCycles)) |
|||
.reduce(a => a.concat(a.map(x => 1 - x)), [0]) |
|||
.join(''); |
|||
// GENERIC FUNCTION |
|||
// range :: Int -> Int -> [Int] |
|||
let range = (m, n) => Array.from({ |
|||
length: Math.floor((n - m)) + 1 |
|||
}, (_, i) => m + i); |
|||
// TEST |
|||
return thueMorse(6); |
|||
// 0110100110010110100101100110100110010110011010010110100110010110 |
|||
})(); |
|||
</lang> |
|||
{{Out}} |
|||
<pre></pre> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |