Thread: Urgent help regarding sequence required

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    2

    Urgent help regarding sequence required

    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

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,537
    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.

  3. #3
    Registered User
    Join Date
    Aug 2019
    Location
    Inside a Singularity
    Posts
    189
    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.

  4. #4
    Registered User
    Join Date
    Oct 2019
    Posts
    2
    A code would do please, thanks.

  5. #5
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,526
    Quote Originally Posted by Euno View Post
    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; 10-31-2019 at 11:32 PM.

  6. #6
    Registered User
    Join Date
    Aug 2019
    Location
    Inside a Singularity
    Posts
    189
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent Help Required
    By rahully2j in forum C++ Programming
    Replies: 13
    Last Post: 04-28-2011, 08:56 PM
  2. urgent help required.
    By theabc in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2011, 11:04 AM
  3. help required urgent!!
    By ikj in forum C++ Programming
    Replies: 2
    Last Post: 05-28-2009, 10:15 AM
  4. Urgent Help required.. pls help ??
    By intruder in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2003, 01:05 PM
  5. Urgent help required
    By sweets in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2002, 01:17 PM

Tags for this Thread