您必须创建一个关闭的Box样式的程序(不是函数,程序)。关闭盒子的基本方法是:
玩家试图通过转动一组标有1-9的杠杆来关闭盒子.他们必须通过翻转杠杆来做到这一点。每个回合的事件顺序如下:
123456789。-。例如,在关闭1、5和9的游戏中,输出将是-234-678-。程序
You rolled: (注意空格)输出滚的值。How many levers to flip: (注意空格)切换杠杆的数量。Which lever to flip: (注意空格)。Game Over。You win!。123456789
You rolled: 5
How many levers to flip: 5
Which lever to flip: 1
Which lever to flip: 2
Which lever to flip: 3
Which lever to flip: 4
Which lever to flip: 5
Game Over123456789
You rolled: 5
How many levers to flip: 3
Which lever to flip: 2
Which lever to flip: 2
Which lever to flip: 1
Game Over123456789
You rolled: 12
How many levers to flip: 2
Which lever to flip: 3
Which lever to flip: 9
12-45678-
You rolled: 6
How many levers to flip: 2
Which lever to flip: 2
Which lever to flip: 4
1---5678-
You rolled: 11
How many levers to flip: 2
Which lever to flip: 5
Which lever to flip: 6
1-----78-
You rolled: 8
How many levers to flip: 1
Which lever to flip: 8
1-----7--
You rolled: 8
How many levers to flip: 2
Which lever to flip: 1
Which lever to flip: 7
---------
You win!发布于 2016-02-01 19:01:04
由于保存了5个字节。
由于DSM保存了7个字节。
噢,这是一个很长的时间。我也讨厌没有一个好的方法来做测试用例。
from random import*
*l,='123456789'
q=['-']*9
r=randint
p=print
f=' to flip: '
while l!=q:
p(*l,sep='');t=r(1,6)+r(1,6)*(l[6:]!=q[6:]);p('You rolled: %s'%t);d={int(input('Which lever'+f))for _ in' '*int(input('How many levers'+f))}
if len(set(d))-len(d)+1-all(str(x)in l for x in d)+t-sum(d):exit('Game Over')
for x in d:l[x-1]='-'
p('You win!')https://codegolf.stackexchange.com/questions/70659
复制相似问题