6 kyu

Look and say sequence generator

381 of 867GiacomoSorbi

Description:

The look and say sequence is a sequence in which each number is the result of a "look and say" operation on the previous element.

Considering for example the classical version startin with "1": ["1", "11", "21, "1211", "111221", ...]. You can see that the second element describes the first as "1(times number)1", the third is "2(times number)1" describing the second, the fourth is "1(times number)2(and)1(times number)1" and so on.

Your goal is to create a function which takes a starting string (not necessarily the classical "1", much less a single character start) and return the nth element of the series.

Examples

 "1",  1 --> "1"
 "1",  3 --> "21"
 "1",  5 --> "111221"
"22", 10 --> "22"
"14",  2 --> "1114"

Trivia: "22" is the only element that can keep the series constant.

Strings
Regular Expressions
Fundamentals

Stats:

CreatedMay 23, 2017
PublishedMay 23, 2017
Warriors Trained1986
Total Skips47
Total Code Submissions2851
Total Times Completed867
JavaScript Completions310
Ruby Completions62
Python Completions381
Crystal Completions7
C# Completions79
C Completions84
Haskell Completions5
Total Stars58
% of votes with a positive feedback rating95% of 249
Total "Very Satisfied" Votes226
Total "Somewhat Satisfied" Votes22
Total "Not Satisfied" Votes1
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • GiacomoSorbi Avatar
  • ZozoFouchtra Avatar
  • anter69 Avatar
  • KataSideKick Avatar
  • hobovsky Avatar
  • dmercertaylor Avatar
  • dfhwze Avatar
  • tobeannouncd Avatar
  • Just4FunCoder Avatar
  • farhanaditya Avatar
  • saudiGuy Avatar
Ad