Skip to content
BytePatterns

Look and Say Term

EasyRecursion#recursion#run-length~15m

Problem

The look-and-say sequence starts with "1". Each later term is made by reading the previous term aloud in runs of equal digits: "1" is one 1, giving "11"; "11" is two 1s, giving "21"; "21" is one 2 then one 1, giving "1211". Given n of at least 1, return the n-th term as a string.

Examples

Input:  n = 4
Output: "1211"
Input:  n = 5
Output: "111221"
Why:    "1211" reads as one 1, one 2, two 1s
Input:  n = 1
Output: "1"
Why:    edge case, the first term is given, nothing to describe

Hints

0 / 3

Stuck on the idea rather than the code? Recursion Basics covers it.