星期五下午晚些时候,你和你的朋友决定那天晚上晚些时候去酒吧,但在去酒吧之前,你应该喝点饮料。然而,事态迅速升级;本周早些时候,你的朋友夏多克·潘普姆索斯中了彩票,并决定用不同的饮料把箱子放在板条箱上。酒馆的保安非常严格,如果你在试图进入酒店前过度消费,你是不允许进入的。不过,你们都是程序员--所以你觉得事情会变得很好。
你需要设计一个酒精计,如果你超过/低于合理的酒吧限制,它会输出真实/虚假的信息。在你下楼去酒吧之前,你要输入你晚上喝过的量和饮料类型到stdin,你的测量程序是这样写的。如果它输出的是真实的,你就会超出酒吧的限制,呆在家里。如果它输出的是假的,你就可以走了。
一个比0大的整数,它代表你的体重(以公斤为单位),后面跟着一个换行符。这一输入后面是一系列一位数的数量和饮料,格式如下:
<amount><amount type>o<beverage type>一瓶啤酒看起来是这样的:
1Bob每个输入都由一个空格分隔。
每种饮料都有一个对应于它所造成的影响的单位。如果你消耗的单位比你的体重除以二,酒吧不再是一种选择。
(这可能反映现实,也可能不反映现实)
以下为有效饮品及相应的酒类单位:
b,1单元e,0单位h,2 (烈性食品)j,0单位r,6单位t,7单位v,6单位w,3单位有不同的数额类型:
BCGKS每一种量都有一个乘数,将其中所含饮料的酒精单位乘以:
3252500.2如果消耗的量大于或低于体重除以2,则程序应将真/假输出到stdout。如果消耗的量等于体重除以2,则应输出错误。
可能输入和输出的
70
1Bob 3SojFalse2
1Cov150
1Cob0100
4Gow 1Koe 1Bov 1Gow 2SotTrue以字节为单位的最短程序获胜!
发布于 2015-11-15 05:49:07
6:B50:C2*:K4:G.4:S];q"behjrtvwo ""10206763*"er~*]:-U<在CJam解释器网上试一试。
6:B e# Push 6 and save it in B.
50:C e# Push 50 and save it in C.
2*:K e# Multiply by 2 to push 100 and save it in K.
4:G e# Push 4 and save it in G.
.4:S e# Push 0.4 and save it in S.
e#
e# The letters representing the types will now push its doubled
e# (to avoid diving the weight by 2) associated multiplier.
]; e# Clear the stack.
q e# Read all input.
"behjrtvwo " e# Push the string of beverages, concatenated with "o ".
"10206763*" e# Push the string of associated units of alcohol and '*'.
er e# Transliterate. This replaces each beverage letter with the
e# associated units of alcohol, and each 'o' and ' ' with '*'.
e#
e# For example, the input
e# 70
e# 1Bob 3Soj
e# is transformed into
e# 70
e# 1B*1*3S*0
e#
~ e# Evaluate the resulting string.
e#
e# For the example this does the following:
e# + Push 70.
e# + Push 1, push 6, multiply, push 1, multiply.
e# + Push 3, push 0.4, multiply, push 0.
e#
* e# Multiply the last two (for the lack of a trailing space).
] e# Collect all results in an array.
:- e# Reduce by subtraction; subtract all other elements from the
e# first element (body weight).
U< e# Compare the result with 0.发布于 2015-11-12 21:26:19
现在我们在用蛇打高尔夫球!
保存了18个字节,这要归功于shebang。
由于DSM,节省了4个字节。
多亏了tzaman,节省了很多字节。
这要感谢扎曼滥用.find()的绝妙技巧,如果它找不到值的话,就会返回-1。
目前,这假设这种饮料格式正是它在挑战中所陈述的方式,例如,每种饮料只有1位数的价值。
w=input()
print(sum([6,50,4,100,.4]['BCGKS'.find(b)]*int(a)*int('1267730'['bhrtvw'.find(v)])for a,b,_,v in input().split())>int(w))发布于 2015-11-15 05:28:22
ldlS/{A,s"CbretjvwSBK"+f#A,[25X6T7T6Z.2Z50Y]+f=:*-}/0<有点微妙,而且可能不太理想,但我认为这样做还行。在网上试试。
ld Read first line, convert to double
lS/ Read second line, split by space
{...}/ For each item in the second line...
A,s"..."+f# Get index in "0123456789CbretjvwSBK", or -1 if not found
A,[...]+f= Index into [0 1 2 3 4 5 6 7 8 9 25 1 6 0 7 0 6 3 0.2 3 50 2]
:* Take product
- Subtract from weight
0< Check if < 0注意,数字数组的末尾有2,这意味着第一个字符串中缺少的Gho被映射到2。
https://codegolf.stackexchange.com/questions/63686
复制相似问题