?dsiZdsl[[]r1-d0<m]dsmxklixzll-2%B*C1+P
输入字符串是从STDIN读取的,格式应为 [yynynynynyyn]
。
dc的字符串处理方式并不为人所知,但在这里,我们足以使它正常工作。这里的方法是对n
s 进行计数,并y
在偶数或n
奇数时输出。这是通过将输入字符串作为宏执行来完成的。 dc
将为'y' (0171) unimplemented
所有y
s 输出错误,并尝试弹出字符串并为所有n
s 打印它们。因此,首先我们要确保[]
要弹出的堆栈中有很多(总输入字符串长度)空字符串。然后我们执行输入字符串,看看[]
堆栈上还剩下多少。从中减去原始字符串的长度即可得出(-ve)的总数n
s。剩下的是做mod 2的算术运算,并输出正确的ASCII y
或n
。
?dsi # Read input string, duplicate, store in register i
Zdsl # Get input length, duplicate, store in register l
[ ] # define macro to:
[] # push empty string
r # swap empty string and remaining length
1- # subtract 1 from length
d0 # duplicate and compare with 0
<m # if >0 recursively call this macro again
dsmx # duplicate macro, store in register m and execute
k # discard left-over 0
lix # load input string and execute as macro
z # get stack length
ll- # load string length and subract
2% # mod 2 (result is -ve because difference is -ve)
B* # multiply by 11 ('y' - 'n')
C1+ # add 121 ('y')
P # print result as ASCII char
在线尝试!