Undulating numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|J}}: presort undul numbers - this could be made more efficient by sorting when the base is chosen)
m (→‎{{header|J}}: efficiency note)
Line 238: Line 238:


fmt7=: 7{{' '-.~":m&#.inv y}}</syntaxhighlight>
fmt7=: 7{{' '-.~":m&#.inv y}}</syntaxhighlight>

As an aside, undul could have been made more efficient, if speed was a concern, precalculating and sorting the digit pairs when the base was choosen:

<syntaxhighlight lang=J>undul=: {{ m {{ m #. y$"1 n}} (/:~ (<:m)}.(,|."1)2 comb m) }}</syntaxhighlight>


We get:
We get: