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

  • Home
  • SEARCH
  • 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 7810777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:55:06+00:00 2026-06-02T03:55:06+00:00

I have a list B=[0,0,0,0,0,0,0,0,0] but it can be any length. I am trying

  • 0

I have a list B=[0,0,0,0,0,0,0,0,0] but it can be any length.

I am trying to iterate through all possible values I can place in B by iteration. When some condition C is met, I want to “reset” the element I just iterated and bump the next item up by 1. Sort of like binary:

000 becomes 001 but then when we increase to 002, condition C is met so we drop it to 0 and increment the next column: 002 becomes 010, etc.

Sorry if I explained that poorly.

So B might go from

B=[0,0,0,0,1,2,5]
to
B=[0,0,0,0,1,2,6]
to
B=[0,0,0,0,1,2,7]

and so forth.

But when condition C is met, I want to reset in this way:

B=[0,0,0,0,1,2,96]
...attempt to increment
B=[0,0,0,0,1,2,97]
...attempt to increment
Condition C met
B=[0,0,0,0,1,3,0]

And be able to do this until I eventually hit condition C on the far left element (equivalent to hitting 1111111 and being unable to increase it any more).

For the sake of easier coding let’s say condition C = the sum of all the numbers exceeds 100.

My attempt (as requested by agf):

B=[0,0,0,0,0,0,0,0]
lenB=len(B)

while sum(B)<=100: #I think I have to somehow account for having tried incrementing the far left instead
    B[lenB-1]+=1 #increment last value in B
    while sum(B)>100: #if the sum is greater than 100
        B[lenB-1]=0 #reset the far right element
        B[lenB-2]+=1 #increment the next element
        #but this is wrong because it needs to perform this check again and again
        #for every column, while also checking if B[len-1] or B[len-2] even exists

EDIT: My Condition C in reality is MUCH more complex than simply checking if Sum(B)>100. I’m just using this as a dummy condition because I can simply replace “if sum(B)>100” with my more complex conditional function.

  • 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-06-02T03:55:09+00:00Added an answer on June 2, 2026 at 3:55 am

    Does this do what you want?

    B=[0,1,0]
    
    def check(ll,callback):
        """
        This function only works if you 
        increment the last element in the list.
        All other incrementing is done in this function.
        """
        for idx in reversed(range(len(ll))):
            if(callback(ll)):
                ll[idx]=0
                ll[idx-1]+=1
            else:
                break  #this index wasn't updated, so the next one won't be either.
    
        #a check to see if every element is 1
        return all(map(lambda x: x==1,ll))
    
    def checksum(ll):
        return True if sum(ll)>100 else False
    
    count=0
    while True:
        count+=1
        B[-1]+=1
        if(check(B,checksum)): break
        print B
    
    print B   # [1,1,1]
    print count
    

    Even for this example, we run through over 5000 iterations before [1,1,1]

    EDIT

    Added a simple break statement as it is only necessary to check the list as long as it changed during the last iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that generates a List<string[]> variable but can't quite figure out how
I have been searching but unable to find a proper list. Can someone please
I'm trying to generate all possible lists of Length N that sum to S.
i neeed something like this in C#.. have list in class but decide what
I have a List of ADUsers but foreach ADUSER I want to get its
I have to implement a one linked list but it should put object in
I have list of files which contain particular patterns, but those files have been
I have read up on remove the character 'u' in a list but I
I have a custom listview, i successfully parse the data into a list but
I have a custom list menu style but I am unsure how to align

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.