Look-and-say sequence: Difference between revisions

Content deleted Content added
Line 2,910: Line 2,910:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
The function:
The function:
<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 *arbitrary* positive integer, and generates the next member of the ‘Look and Say’ sequence.


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


<lang Mathematica>NestList[LookAndSay, 1, 12] // Column</lang>
<lang Mathematica>NestList[LookAndSay, 1, 12] // Column</lang>

returns


<pre style='height:15em;overflow:scroll'>1
<pre style='height:15em;overflow:scroll'>1
Line 2,934: Line 2,932:
1321132132111213122112311311222113111221131221</pre>
1321132132111213122112311311222113111221131221</pre>


The second example returns the next 12 numbers of the sequence starting with 7:
Entering 7:


<lang Mathematica>NestList[LookAndSay, 7, 12] // Column</lang>
<lang Mathematica>NestList[LookAndSay, 7, 12] // Column</lang>

generates:


<pre style='height:15em;overflow:scroll'>7
<pre style='height:15em;overflow:scroll'>7