How to design an algorithm to calculate countdown style maths number puzzle

后端 未结 10 1143
清酒与你
清酒与你 2020-11-30 00:35

I have always wanted to do this but every time I start thinking about the problem it blows my mind because of its exponential nature.

The problem solver I want to be

10条回答
  •  一向
    一向 (楼主)
    2020-11-30 01:23

    I wrote a slightly simpler version:

    1. for every combination of 2 (distinct) elements from the list and combine them using +,-,*,/ (note that since a>b then only a-b is needed and only a/b if a%b=0)
    2. if combination is target then record solution
    3. recursively call on the reduced lists

提交回复
热议问题