> <>,视网膜,Python的2:144 127 123字节
@Loovjo通过删除空格节省了1个字节
@ mbomb007通过使用input
代替来节省了4个字节raw_input
#v"PAPER"v?%4-2{"SCISSORS"v?%2:i
#>ooooo; >oooooooo<"ROCK"~<
a="KRS".index(input()[-1])
print["SCISSORS","ROCK","PAPER"][a]
在TNB上发布的挑战,我决定尝试这种语言组合。
> <>
在线尝试!
IP开始向右移动。
# Reflect the IP so that it now moves left and it wraps around the grid
i: Take one character as input and duplicate it
输入中可能使用的字符为PRS
(因为程序仅采用第一个字符)。他们的ASCII值是80
,81
和82
。
2% Take the modulo 2 of the character. Yields 0, 1, 0 for P, R, S respectively
?v If this value is non-zero (ie the input was ROCK), go down, otherwise skip this instruction
如果输入是固定的,则将发生以下情况:
< Start moving to the left
~ Pop the top most value on the stack (which is the original value of R and not the duplicate)
"KCOR" Push these characters onto the stack
< Move left
oooo Output "ROCK" as characters (in turn these characters are popped)
o Pop the top value on the stack and output it; but since the stack is empty, the program errors out and exits promptly.
否则,如果输入为SCISSORS
或PAPER
,则IP将会遇到以下情况:
"SROSSICS" Push these characters onto the stack
{ Shift the stack, so the the original value of the first char of the input would come to the top
2-4% Subtract 2 and take modulo 4 of the ASCII-value (yields 2, 0 for P, S respectively)
?v If it is non-zero, go down, otherwise skip this instruction
如果输入为PAPER
,则:
>ooooooooo Output all characters on the stack (ie "SCISSORS")
< Start moving left
o Pop a value on the stack and output it; since the stack is empty, this gives an error and the program exits.
否则(如果输入为SCISSORS
):
"REPAP" Push these characters onto the stack
v>ooooo; Output them and exit the program (without any errors).
视网膜
在线尝试!
在这种情况下,视网膜将两行中的每对视为一对匹配和替换。例如,它尝试将与第一行匹配的任何内容替换为第二行,但是由于第一行从不匹配,因此从不将其替换为任何内容,从而保留了输入。
Python 2
在线尝试!
Python程序需要将输入放在"
s 之间。
前两行是Python中的注释。
a="KRS".index(input()[-1]) # Get the index of the last character of the input in "KRS"
print["SCISSORS","ROCK","PAPER"][a] # Print the ath index of that array