一个数字迷宫题(需要用计算机编程实现,最好matlab)

Start at 2011. By moving through the maze and doing any arithmetic operations you encounter, exit the maze with a result of 2012. You may pass through an operation several times, but not twice in a row.

注意:除2选择向下取整

http://www.matrix67.com/blog/archives/4790

1 个回答

我说我看不懂这英文行么。。

coding=utf-8

language:Python

num1 = 2011
num2 = 2012

had_found = False
for i1 in ["+7", "/2"]:
for i2 in ["*3", "-5"]:
num3 = int(eval(str(num1)+i1+i2))
if num3 == num2:
print "%s%s%s=%s" % (num1, i1, i2, num3)
had_found = True
break
if not had_found: print '没找到符合条件的表达式..'

对不对?这题目没有实例可供测试。

发代码真蛋疼。。Screenshot