Thue-Morse: Difference between revisions
Content added Content deleted
m (→JS ES6) |
m (→using functions: used a template for the output section.) |
||
Line 1,480: | Line 1,480: | ||
<lang rexx>/*REXX pgm generates & displays the Thue─Morse sequence up to the Nth term (inclusive). */ |
<lang rexx>/*REXX pgm generates & displays the Thue─Morse sequence up to the Nth term (inclusive). */ |
||
parse arg N . /*obtain the optional argument from CL.*/ |
parse arg N . /*obtain the optional argument from CL.*/ |
||
if N=='' | N=="," then N= |
if N=='' | N=="," then N= 80 /*Not specified? Then use the default.*/ |
||
$= /*the Thue─Morse sequence (so far). */ |
$= /*the Thue─Morse sequence (so far). */ |
||
do j=0 to N /*generate sequence up to the Nth item.*/ |
do j=0 to N /*generate sequence up to the Nth item.*/ |
||
$=$ || $weight(j) // 2 |
$= $ || $weight(j) // 2 /*append the item to the Thue─Morse seq*/ |
||
end /*j*/ |
end /*j*/ |
||
say $ |
say $ |
||
Line 1,490: | Line 1,490: | ||
$pop: return length( space( translate( arg(1), , 0), 0) ) /*count 1's in number.*/ |
$pop: return length( space( translate( arg(1), , 0), 0) ) /*count 1's in number.*/ |
||
$weight: return $pop( x2b( d2x( arg(1) ) ) ) /*dec──►bin, pop count*/</lang> |
$weight: return $pop( x2b( d2x( arg(1) ) ) ) /*dec──►bin, pop count*/</lang> |
||
{{out|output|text= when using the default input:}} |
|||
<pre> |
<pre> |
||
01101001100101101001011001101001100101100110100101101001100101101001011001101001 |
01101001100101101001011001101001100101100110100101101001100101101001011001101001 |
||
</pre> |
</pre> |
||
===using in-line code=== |
===using in-line code=== |