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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:37:10+00:00 2026-05-15T15:37:10+00:00

I’ve got a real problem (it’s not homework, you can check my profile). I

  • 0

I’ve got a real problem (it’s not homework, you can check my profile). I need to parse data whose formatting is not under my control.

The data look like this:

6,852:6,100,752

So there’s first a number made of up to 9 digits, followed by a colon.

Then I know for sure that, after the colon:

  • there’s at least one valid combination of numbers that add up to the number before the column
  • I know exactly how many numbers add up to the number before the colon (two in this case, but it can go as high as ten numbers)

In this case, 6852 is 6100 + 752.

My problem: I need to find these numbers (in this example, 6100 + 752).

It is unfortunate that in the data I’m forced to parse, the separator between the numbers (the comma) is also the separator used inside the number themselves (6100 is written as 6,100).

Once again: that unfortunate formatting is not under my control and, once again, this is not homework.

I need to solve this for up to 10 numbers that need to add up.

Here’s an example with three numbers adding up to 6855:

6,855:360,6,175,320

I fear that there are cases where there would be two possible different solutions. HOWEVER if I get a solution that works “in most cases” it would be enough.

How do you typically solve such a problem in a C-style bracket language?

  • 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-15T15:37:11+00:00Added an answer on May 15, 2026 at 3:37 pm

    Recursive implementation (pseudo code):

    int total;  // The total read before the colon
    
    // Takes the list of tokens as integers after the colon
    // tokens is the set of tokens left to analyse,
    // partialList is the partial list of numbers built so far
    // sum is the sum of numbers in partialList
    // Aggregate takes 2 ints XXX and YYY and returns XXX,YYY (= XXX*1000+YYY)
    function getNumbers(tokens, sum, partialList) =
        if isEmpty(tokens)
             if sum = total return partialList
             else return null  // Got to the end with the wrong sum
        var result1 = getNumbers(tokens[1:end], sum+token[0], Add(partialList, tokens[0]))
        var result2 = getNumbers(tokens[2:end], sum+Aggregate(token[0], token[1]), Append(partialList, Aggregate(tokens[0], tokens[1])))
        if result1 <> null return result1
        if result2 <> null return result2
        return null  // No solution overall
    

    You can do a lot better from different points of view, like tail recursion, pruning (you can have XXX,YYY only if YYY has 3 digits)… but this may work well enough for your app.
    Divide-and-conquer would make for a nice improvement.

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

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
I've got a string that has curly quotes in it. I'd like to replace
I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.