number finding

Pages: 12
<rushed, ignorant post removed>
2nd try:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>

const int GOAL_SUM = 1286;
const int RANGE_MIN = 97;
const int RANGE_MAX = 122;

//arr[i] will represent how many ways we can get a sum of i
unsigned long long arr[GOAL_SUM + 1] = {0LL};

int main()
{
    //initially we'll say there's one way to sum up to each of our range
    //values (using the number by itself)
    for(int i = RANGE_MIN; i <= RANGE_MAX; ++i)
    {
        arr[i] = 1;
    }

    //for all numbers in the range
    for(int i = 0; i <= GOAL_SUM; ++i)
    {
        //if we reach a term (i) that we can obtain a sum for...
        if(arr[i] != 0)
        {
            //then this term (i) plus a number in our range (j) gives
            //a term (i+j) that can be acheived through sums in as
            //many ways as the term (i) can be.
            for(int j = RANGE_MIN; j <= RANGE_MAX; ++j)
            {
                if( (i + j) <= GOAL_SUM)
                {
                    arr[i + j] += arr[i];
                }
            }
        }
    }

    std::cout << "Ways to sum up to " << GOAL_SUM << " with numbers in range "
              << RANGE_MIN << "-" << RANGE_MAX << ": " << arr[GOAL_SUM] << '\n';
}

Ways to sum up to 1286 with numbers in range 97-122: 828992523542781


EDIT: clarified a comment
Last edited on
Thank you Tition for your wonderful answer and I am sorry to confuse you as I could not post all the challenge but only this 25 % part of it , which is very essentia,l because I cannot do it by respect for the person who made the challenge and as I need to solve it alone too
Thanks booradley60, wonderful answer for the number of partitions!

I should have thought of that myself ... My consolation prize is that the number of partitions you got,

828992523542781

divided by the number I guessed, 25^10 =

95367431640625

is off only by a factor of 8 (I wasn't even off by an order of magnitude!). Muhahaha!

And your code is great, if you don't mind I will use your idea in my main code (I will re-factor it of course). How would you like to be acknowledged in the comments?

To dliver:

This means there will be approximately

~12 600 000 000 solutions to your problem (12.6 trillion billion). Writing a program to give you a database with those sounds like a very large problem.
Last edited on
@tition
I don't mind either way whether or not you make the acknowledgement, but I do appreciate your asking! I only went over the logic a few times, so caveat emptor!
~12 600 000 000 solutions to your problem (12.6 trillion).
*cough* billion *cough*. Actually never mind I just remembered that other countries start with thousand instead of hundred or some kind of different number convention
Last edited on
"To dliver:

This means there will be approximately .."

there is a probability that the 25 % is used to distract and confuse the challenger and if your approximation is right , I would say that , may be , my whole challenge can be solved without using a program at all . I will see
Topic archived. No new replies allowed.
Pages: 12