Given the first value, generate the next seven terms of the sequences like 1, 11, 21, 1211,
111221, 312211, 13112221, 1113213211.
I know how to generate a particular term but I am unable to do this
Given the first value, generate the next seven terms of the sequences like 1, 11, 21, 1211,
111221, 312211, 13112221, 1113213211.
I know how to generate a particular term but I am unable to do this
Seems familiar....
Building a Logic! - C++ Forum
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I think I recognise that pattern from a TED-ed Video that I saw a long time ago.... I can't find the actual video right now but I this is a similar copy of the video by someone else that popped up first as per what I searched.
YouTube
You've already figured out the logic for finding the next term if you solve manually but coding the same thing in a loop is quite difficult. Try counting the longest sequence of same numbers together and add the count with the current sequence number being counted to a string.
Ex: 11122
Count longest string of same numbers together...
3 1's
Add the 3 and 1 to your string
Continue parsing the string to find the next longest string of same numbers...
2 2's
Add 2 and 2 to your string
.
.
.
(for different kinds of inputs)
There is someone who devised a mathematical solution to determine the N'th term of the sequence but I cannot remember/find the link to where I saw a more efficient solution compared to what I had made as my solution literally parsed through 7 of the previous string of numbers to find the 8th number.
A code would do please, thanks.
I don't think "a code" (LMAO) is necessary since code (in lots of languages, including C++) for generating and printing this sequence is available all over the place and a simple google search away.
Edit: If you cannot use google to find the solution or write the solution yourself (both options are so trivial that a 5-year-old could do it), perhaps you should give up on programming. Just a thought. All your code are belong to us.
Last edited by Hodor; 3 Weeks Ago at 11:32 PM.
If you insist on a solution without trying first (i.e. provide us a code where we can see what you've tried), then I agree to what @Hodor has to say....
Here you go:
Look-and-Say Sequence - GeeksforGeeks
I can't find the more efficient solution that I mentioned in my #3 post though.... don't know what I'd googled the last time I ever saw the solution