M
M
Max Payne2017-10-20 13:28:53
Programming
Max Payne, 2017-10-20 13:28:53

What could be alternative ways to solve this problem?

Attention! This is NOT a task, you DO NOT need to write code that solves this problem, I'm interested in alternative IDEAS for solving the problem, not their implementation.
There are two numbers, let N and S. S is the cost of a certain product, N is the number of coins 1...N, that is, 1,2,3...
N :

N=3
S=5
Варианты:
2+3=5
________________________
N=4
S=4
Варианты:
1) 4=4
2) 1+3=4

The simplest solution in the forehead is with the help of recursion, but what other solutions can there be? For some reason, it seems to me that this can be solved using a formula, but I cannot figure out which one.
And once again:
Attention! This is NOT a task, you DO NOT need to write code that solves this problem, I'm interested in alternative IDEAS for solving the problem, not their implementation.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-10-20
@webinar

I think all the options are here: the possible sums of numbers
are also very important here, that in N, if there can be any integer, this is one option. If fractional, another. If there are all possible integers, but no more than the value of S - the third one. As far as I understand the third option. That is, you need to calculate all possible combinations to get the sum of two integers equal to S.
By the way, there is a cool video, mathematical methods for calculating the probability of getting a "lucky ticket" in transport are analyzed. In fact, your case, since it is the calculation of possible amounts:
https://www.youtube.com/watch?v=mqnnCdIlBKU (watch from the 3rd minute, there are a lot of lyrics at the beginning) I can’t say that the situation is 1v1, but the calculation method will be the same.

G
Griboks, 2017-10-20
@Griboks

I would use combinatorics.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question