Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:28:40+00:00 2026-05-24T10:28:40+00:00

I would like to introduce look-and-say sequence at first. It goes like a =

  • 0

I would like to introduce look-and-say sequence at first. It goes like a = {1, 11, 21, 1211, 111221 ...

The system is it checks the previous digit and counts the numbers.

1 = one 1 (so = 11)
11 = two 1 (so = 21)
21 = one 2 one 1 (so = 1211)

As a rule of the sequence, no number can go beyond 3, so creating a translation table can fit in. But it is not semantic, I don’t like it.

What I want is, a script which evaluates the given value and return a look-and-say-alike string.

However, to go beyond out limits, I want it to even evaluate chars, so it can return 1A2b41.

I have been trying to make it work for hours, the logic went bad and I am having a brainfreeze at the moment.

Here is the script that actually doesn’t work(returns false results), but it can give you the idea, at least.

def seq(a):
    k,last,result,a = 1,'','',str(a)
    for i in range(len(a)):
        if last==a[i]:k+=1
        else:
            result = result+str(k)+a[i]
            k=1
        last = a[i]
    return result
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:28:41+00:00Added an answer on May 24, 2026 at 10:28 am

    I can see two issues with your code:

    • The result is expanded by k and a[i] although the counter k does not count chars a[i] but chars last. Replace a[i] by last here (you may not want to add anything in the first round).

    • After the loop you have to add the last value of the counter together with the last character again (this was not yet done), i.e. add another result = result+str(k)+last after the loop.

    In total it looks like

    def seq(a):
        a = str(a)
        k,last,result = 1,a[0],''
        for i in range(1,len(a)):
            if last==a[i]:k+=1
            else:
                result = result+str(k)+last
                k=1
            last = a[i]
        result = result+str(k)+last
        return result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to introduce multithreading feature in my shell script. I have a
I have a JSF application that uses mostly Richfaces. I would like to introduce
I'm fairly new to the world of versioning but would like to introduce Subversion
I want to introduce a Facebook-like likes system, in that my members can click
I would like to introduce some javascript <script>xxx</script> content into my generated index.html in
I am developing inherited jsp/java ee application and I would like to introduce Guice
JavaFX is a new technology introduced by Sun. I would like to know what
Would like to be able to set colors of headings and such, different font
Would like to know what a programmer should know to become a good at
Would like to make anapplication in Java that will not automatically parse parameters used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.