Answer the question
In order to leave comments, you need to log in
How to solve the problem in the arrangement of arithmetic signs in Python?
Good afternoon met with the following task. I saw a similar code somewhere, but now I can not find it. The essence of the problem is that you specify N numbers (and they may not be integers). The main task is to arrange the signs "+" and "-" so that in the end you get a certain number.
For example, 3 numbers are given for input: 1983, 86, 2032. It is necessary to determine for which combination they will end up with a number: 135. That is, it is necessary to determine the positions of the numbers and the arithmetic signs between them. And the input can be given about 100 numbers. Therefore, a simple enumeration is annoying.
The combination of the solution is 2032 - 1983 + 86 = 135. How can I implement this in Python code? And is it possible?
Answer the question
In order to leave comments, you need to log in
Recently I watched a JavaScript tutorial on habrahabr.ru. Organized as a set of posts on Habré. There was a similar solution in the section about recursion. See if this is what you need
This task is purely algorithmic. Therefore, it can be solved in any language that has Turing completeness. Python is such a language.
How to implement? You draw up an algorithm on paper, then implement it, as always. No one will write the algorithm for you.
If you are confused by exhaustive search - look at genetic algorithms. Once upon a time in the university they still solved this particular problem with general algorithms - it worked great. Well, or in Google, I think there are a lot of algorithms.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question