随笔(Blackout Math)
这两天碰到了一个比较有意思的问题,说起来最近见到了不少用程序来解puzzle的问题描述,这里给大家介绍一下:
Blackout Math
For example, given the equation
6 - 5 = 15 ^ 4/2
we can remove the digit 5 and the / operator from the right-hand side in order to obtain the correct equality
6 - 5 = 1 ^ 42.
Both sides of the equation now equal to 1.Observe how removing an operator between two numbers (4 and 2) causes the digits of the numbers to be concatenated (42). Here is a more complicated example: 288 / 24 x 6 = 18 x 13 x 8
We can remove digits and operators from either side of the equals sign (either both from one side, or one on each side). In this case, we can remove the 2 from the number 24 on the left-hand side and the 1 from the number 13 on the right-hand side to obtain the correct equality
288 / 4 x 6 = 18 x 3 x 8 Both sides of the equation now equal to 432.
上面给出的问题描述就是对该puzzle的解释,也就是如何从上式中移除掉两个元素保证式子左右满足等式关系。
解决思路
针对给定的一个式子,去除的方法总数应为 C n − 1 2 C_{n - 1}^{2} Cn−12(因为等号本身是不可以被去除的),因此可以采用暴力求解的办法去求取,通过生成随机下标的方法删除任意两个元素获取新的等式,然后计算等式两边是否相等。
关于等式两边数值的求解问题,这里可以采用简单的计算器求解等式的思路,即设定两个堆栈进行求解。
具体的实现后面会在博客中给出😁