CJam,22岁
A:<empty>
B:{])`\,q,K/(*))*"_~"}
C:{])`\,q,K/(*))*"_~"}_~
示例运行:
ABBC(ABC) -> ABBBC
转化为
{])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}_~
输入为
{])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}_~
提供以下输出:
{])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}_~
运作方式:
让我们看一下程序AC
和ABC
外观:
AC :{])`\,q,K/(*))*"_~"}_~
ABC:{])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}_~
我们注意到C
=B_~
让我们看看B
正在做什么:
{])`\,q,K/(*))*"_~"}
{ } e# This is a code block. Alone, this does nothing except
e# pushing this block to stack as is
] e# Wrap everything on stack in an array
)` e# Take out the last part and convert it to its string representation
\, e# Take length of remaining array
q,K/ e# Read the input, take its length and int divide by K (i.e. 20)
(* e# Decrement and multiply by the array length on stack
)) e# Add two to the product
* e# Repeat the string representation on stack that many times
"_~" e# Put this string on stack
现在让我们看看AC
没有任何输入的情况下将执行的操作:
{])`\,q,K/(*))*"_~"}_~ e# Copy the block and run it
{])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}~ e# Block is copied, run it
{ ... } ]) e# Wrapped array has the block in it.
`\, e# Stringify it and take length of remaining = 0
q,K/ e# No input so 0
(*)) e# 0 * -1 = 0. 0 + 2 = 2
* e# Repeat the stringified block 2 times:
e# "{])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}"
"_~" e# Put this string. Program ends, so print stack:
e# {])`\,q,K/(*))*"_~"}{])`\,q,K/(*))*"_~"}_~
哇,输出是ABC
。
我们基本上算出B
代码中有多少个。然后输入多少(使用长度)。将它们相乘,增加两次(C
也有B
),然后追加_~
以获得C
在这里在线尝试