木板游戏神秘主义者对于主要资源之一power有一些非常有趣的机制。不是从银行获得和消耗单位的权力,每个玩家开始游戏的时候,只有12个单位的能量分配在三个“碗”上,标签是I,II和III。获得和消费的权力就在这些碗之间简单地转移力量:
下面是一个例子。例如,播放机从以下功率分配开始(按I | II | III顺序分配):
5 | 7 | 0如果他们获得并花费几次权力,他们的权力就会发生如下变化:
5 | 7 | 0
Gain 3 ==> 2 | 10 | 0
Gain 6 ==> 0 | 8 | 4 (move 2 power from I to II,
then the remaining 4 from II to III)
Gain 7 ==> 0 | 1 | 11
Spend 4 ==> 4 | 1 | 7
Gain 1 ==> 3 | 2 | 7
Spend 7 ==> 10 | 2 | 0
Gain 12 ==> 0 | 10 | 2 (move 10 power from I to II,
then the remaining 2 from II to III)
Gain 12 ==> 0 | 0 | 12 (the two excess units go to waste)您的任务是计算这样一个获取或支出事件的结果。
挑战
您将得到四个整数作为输入。前三个,I,II,III,代表了三个碗中每一个的能量量。他们将是非负的,他们的总和为12。第四个数字,P,是获得或消耗的能量,并将在包容范围内的[-III, 24] (所以你可能会假设玩家永远不会试图花费超过他们目前的能力,但他们可能获得比他们需要的更多的力量,把所有的力量转移到第三碗)。
您可以以任何一致的顺序将这些数字视为单独的参数、整数列表或包含这些整数的字符串。您还可以将P作为一个参数,将I、II、III作为单独的列表参数。
您应该输出三个整数I'、II'、III',它们代表了每个碗中在获得或使用P单元之后的功率量,并遵循了上面解释的规则。
您可以编写一个程序或函数,并使用我们接收输入和提供输出的任何标准方法。
您可以使用任何编程语言,但请注意,默认情况下禁止使用这些漏洞。
这是密码-高尔夫,所以最短的有效答案(以字节为单位)获胜。
I II III P => I' II' III'
5 7 0 3 => 2 10 0
2 10 0 6 => 0 8 4
0 8 4 7 => 0 1 11
0 1 11 -4 => 4 1 7
4 1 7 0 => 4 1 7
4 1 7 1 => 3 2 7
3 2 7 -7 => 10 2 0
10 2 0 12 => 0 10 2
0 10 2 12 => 0 0 12发布于 2017-03-06 20:43:01
{x=#-#4~Min~#,y=Max[#2+#-Abs[#4~Max~0-#],0],12-x-y}&这是一个未命名的函数,它以列表{I, II, III, P}作为输入,并返回列表{I', II', III'}。
封闭形式的解决方案。感觉还不太理想..。
发布于 2017-03-06 20:20:23
def f(i,d,t,g):
x=min(i,g);i-=x;q=g>0;g-=x
if q:d+=x;x=min(d,g);g-=x;d-=x;t+=x
else:t+=x
print i,d,tdef f(i,d,t,g):
if g>0:
x=min(i,g)
g-=x
i-=x
d+=x
x=min(d,g)
g-=x
d-=x
t+=x
else:
x=min(i,g)
g-=x
i-=x
t+=x
print(i,d,t)发布于 2017-03-06 21:12:02
包括-r的+1
/-/!{:
s/1,(.* )1/,1\1/
t}
s/(.*)(1+) -\2/\2\1/
s/(,,1{12}).*/\1/使用一元(参见这个共识)。
/-/!{ # If there is not a '-'
: # start loop
s/1,(.* )1/,1\1/ # move a 1 from before a ',' to after the ',' for every 1 after the space
# sed reads left to right, so this takes everything from the first bowl before starting on the second
t # loop if something changed
} # end if
s/(.*)(1+) -\2/\2\1/ # take all of the 1s from after a '-' and move them to the begining.
# at the same time, remove that many 1s from the 3rd bowl
s/(,,1{12}).*/\1/ # remove everything after 12 1s in the third bowlhttps://codegolf.stackexchange.com/questions/112176
复制相似问题