Look-and-say sequence: Difference between revisions

Content deleted Content added
Line 2,912: Line 2,912:
<lang Mathematica> LookAndSay[n_Integer?Positive]:= Map[Reverse, Tally /@ Split @ IntegerDigits @ n, 2] // Flatten // FromDigits</lang>
<lang Mathematica> LookAndSay[n_Integer?Positive]:= Map[Reverse, Tally /@ Split @ IntegerDigits @ n, 2] // Flatten // FromDigits</lang>


takes an *arbitrary* positive integer, and generates the next member of the ‘Look and Say’ sequence.
takes an <em>arbitrary</em> positive integer, and generates the next member of the ‘Look and Say’ sequence.


The first example returns the next 12 numbers of the sequence starting with 1:
The first example returns the next 12 numbers of the sequence starting with 1: