Challenge - Look and say sequence | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 29

Challenge - Look and say sequence

In mathematics, the look-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ... To generate a member of the sequence from the previous member, read off the digits of the previous member, counting the number of digits in groups of the same digit. For example: 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 is read off as "one 2, then one 1" or 1211. 1211 is read off as "one 1, one 2, then two 1s" or 111221. 111221 is read off as "three 1s, two 2s, then one 1" or 312211. For more info - https://en.wikipedia.org/wiki/Look-and-say_sequence

24th Sep 2017, 11:02 AM
Ekansh
22 Answers
+ 11
Task - Make a code in any language to find the sequence from 1st element to inputted element. Sample input - 5 Sample Output - 1 11 21 1211 111221
24th Sep 2017, 11:01 AM
Ekansh
+ 11
Here's my C# implementation! ✌ I think my solution is quite general and I treat the number in the sequence as string instead of integer as it overflows after the 8th term. Happy coding! 😄 https://code.sololearn.com/c33uCTSQMCaD/?ref=app
24th Sep 2017, 3:46 PM
Zephyr Koo
Zephyr Koo - avatar
25th Sep 2017, 8:42 AM
David Akhihiero
David Akhihiero - avatar
24th Sep 2017, 11:03 AM
Ekansh
+ 6
in Python: most difficult job done by itertools module :( https://code.sololearn.com/cWtXec6j81FM/?ref=app
25th Sep 2017, 2:22 PM
yuri
25th Sep 2017, 4:01 PM
m abrate
m abrate - avatar
29th Sep 2017, 6:08 AM
noobcøder
noobcøder - avatar
+ 5
Read 1 as one 1 and can be written as 1(one) 1 = 11 then 11 = two 1 = 2(two) 1 = 21 then 21 = ....
24th Sep 2017, 1:23 PM
Ekansh
25th Sep 2017, 11:41 PM
paul
27th Sep 2017, 12:25 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
26th Sep 2017, 6:08 PM
ysraelcon
ysraelcon - avatar
+ 2
So interesting! :D
25th Sep 2017, 1:32 PM
Hunt Wolf
Hunt Wolf - avatar
+ 2
Here you go. Checks for valid input. https://code.sololearn.com/cO1854rla0ic/?ref=app
27th Sep 2017, 4:07 AM
Vari93
Vari93 - avatar
+ 2
https://code.sololearn.com/cB2BYfvAv3vZ/?ref=app
27th Sep 2017, 1:03 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 2
Requires 2 numeric inputs, # of iterations & starting value... https://code.sololearn.com/coXzn6Rd1a4P/?ref=app
27th Sep 2017, 4:46 PM
Chillbilly Rube
Chillbilly Rube - avatar
+ 1
here a working example in javascript. Wrote it on the mobile phone so i am going to prettify it later :) https://code.sololearn.com/WV2qkykK7dsH/?ref=app
27th Sep 2017, 12:06 PM
Kevin Saiger
Kevin Saiger - avatar
27th Sep 2017, 11:24 PM
paul
0
sample input 1 sample output 1 11
26th Sep 2017, 8:38 AM
Luckmission
Luckmission - avatar
0
here is my python solution it includes iconic recursion with a mix of single for loop. https://code.sololearn.com/cefSElP3WfBr/#py
23rd Feb 2020, 5:11 PM
mustafa hk
mustafa hk - avatar