Algorithm for permutations of operands and operators

Pages: 12
I'm sure the code is not perfect, but I don't know a way of checking if it found all possible results. But I would say that adding one more value to list of values increases the runtime 5 fold, which is not surprising for a brute force solution.

Actually found a way to paste the output from the program. This is the result I get with 315:

http://anotepad.com/notes/4772443

EDIT:
Maybe if I get time, I will combine my output to yours and using a postfix solver. I will piece together the output you get from yours then take only the unique pieces by placing them in a set then take the set difference to find the ones mine are missing. But you should post your code as well so I can see what you are doing differently to obtain such a large result
Last edited on
Ah, I see now what you're doing. See in my previous post (http://www.cplusplus.com/forum/general/135491/#msg723274 ) the last line on the list. That's a stand-in for all expressions of the form ((((a $ b) $ c) $ d) $ e) $ f, where $ is some operator. You're limiting your search space only to those expressions. There are some expressions that evaluate to 315 and are not of this form, such as 7 * (8 - (3 + 10) + 50).
Ahh yes, I only put brackets around expressions where a '*' or '/' symbol follows a '+' or '-' character. The expression you have posted above is the same as these:

(8 - 3 + 50 - 10) * 7
(8 - 3 - 10 + 50) * 7

But this is another an interesting excercise to find all possible bracket combinations.
There are some expressions that can't be reordered like that. E.g. ((100 - 10) * 7) / (50 / 8 / 3)
Last edited on
Well, I may as well.
http://pastebin.com/1JYATZCX
Topic archived. No new replies allowed.
Pages: 12