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 9232623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:21:28+00:00 2026-06-18T06:21:28+00:00

I’m trying to reverse engineer a legacy report and using python to solve the

  • 0

I’m trying to reverse engineer a legacy report and using python to solve the problem.

The legacy report has an end sum number of 200,000.

I know a collection of the numbers that could end up to this 200k, but this collection is littered with many other numbers that are to be filtered out (with logic i’m yet to understand).

In python, How could i iterate through the list of numbers to find all entries (sub-lists) of variable length (could be 1 element that = 200k, or the product of 15 elements…) that would add up to the 200k?

I started to write it out, then decided to ask for help when i realized element #1 + 2 could overflow but list element #1 + 4 + 7 could be a match to the 200k….

It’s almost like factorization, however with the sum’s instead of the products, and within a list of possible candidates.

Not sure. Any ideas? Anyone ever done anything like this?

Additional Details:
With permutations and numpy i’m getting a result as expected, however it is taking far too long with the expected inputs and outputs. (i.e. days..?)

below is where I am at:

Below seems to give correct results, although it seems it will take awhile.

I’ll accept the answer above and let this run over night.

Thanks,

from itertools import permutations 
import numpy , pickle, random
output_results = {} 
input_array = [random.randrange(0,15000) for i in range(1000)]
desired_sum = 200000
#input_array = (1,2,9,13,12) 
#desired_sum = 23 

for r in range(1,len(input_array)): 
    for p in permutations(input_array, r):
        temp_sum = numpy.sum(p) 
        if temp_sum == desired_sum: 
            output_results[p] = numpy.sum(p) 
    if r % 10 == 0:
        print "Finished up to number %s " % r 

pickle.dump( output_results, open( "save.p", "wb" ) )
  • 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-18T06:21:29+00:00Added an answer on June 18, 2026 at 6:21 am

    Itertools.permutations can help.

    Varying the value of r in permutations(iterable, r) you can try to find all the possible permutations containing r entries from iterable (your collection), of which you can easily get sums (e.g. with numpy.sum).

    If you have some idea of what to expect and set a reasonable upper limit for r you should get an answer in a reasonable time

    edit

    @joefromct: you can first estimate the largest value of r needed to find the solution you want in the following way (is not tested, but the idea should be correct)

    sorted_input = np.sorted(input_array)
    cumsum = np.cumsum(sorted_input)
    max_r = (cumsum<desired_sum).sum()
    if max_r == len(input_array) and sorted_input[-1] < desired_sum:
        print("sorry I can't do anything for you")
        exit()
    
    for r in range(1,max_r):
        [...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am using JSon response to parse title,date content and thumbnail images and place

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.