Anonymous user
Thue-Morse: Difference between revisions
m
→using functions: used a template for the output section.
m (→JS ES6) |
m (→using functions: used a template for the output section.) |
||
Line 1,480:
<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.*/
if N=='' | N=="," then N=
$= /*the Thue─Morse sequence (so far). */
do j=0 to N /*generate sequence up to the Nth item.*/
$= $ || $weight(j) // 2
end /*j*/
say $
Line 1,490:
$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>
<pre>
01101001100101101001011001101001100101100110100101101001100101101001011001101001
</pre>
===using in-line code===
|