I write this game before by Dephi. Algo is simple: 1.穷举 2.限制重复穷举: 1) 4个数 into 2 groups 2) use + - * / get possible values of each group 3) use + - * / get possible values of the results of two groups if 24, bingo 限制重复 a lot of similar expressions are generated, you can give some rules to eliminate them.Examples:2,4,6,91) C(4,2)=6 possibilities. One possibility {(2,4) (6,9)} 2) possible values of (2,4) are {6,2,-2,8,1/2}, (6,9) can generate {15,3,-3,2/3,3/2} 3) 3*8=24=(9-6)*(2*4)
sorry, only c(4,2)/2=3 possibilities
to wobelisk, 你的思路很好啊,不过会丢掉一些结果 比如(1+1+1)*8=24
Peter207, you are right. The algo post here is not complete. If I have time, I can post the algo used in my program which can deal with the case you gave.
1.穷举
2.限制重复穷举:
1) 4个数 into 2 groups
2) use + - * / get possible values of each group
3) use + - * / get possible values of the results of two groups
if 24, bingo
限制重复
a lot of similar expressions are generated, you can give some rules to eliminate them.Examples:2,4,6,91) C(4,2)=6 possibilities. One possibility {(2,4) (6,9)}
2) possible values of (2,4) are {6,2,-2,8,1/2}, (6,9) can generate {15,3,-3,2/3,3/2}
3) 3*8=24=(9-6)*(2*4)
only c(4,2)/2=3 possibilities
你的思路很好啊,不过会丢掉一些结果
比如(1+1+1)*8=24
The algo post here is not complete.
If I have time, I can post the algo used in my program which can deal with the case you gave.