您的任务很简单:编写一个不需要输入和输出(或返回)源代码的程序(或函数)。问题是,当程序用"quotes" (Unicode字符34)包装时,它应该再次输出它的(现在引用的)源代码。
适用奎因的标准规则。这是密码-高尔夫,所以最短的程序(以字节为单位)获胜。
发布于 2021-06-02 00:31:15
D,29字节`Dqp^≈[_\\"pǏ]₴`Dqp^≈[_\"pǏ]₴解释:
`...`Dqp^≈[_\"pǏ]₴
`...` Push half the source code
D Make 3 copies of the source code
qp Uneval the first copy (quote, escape) and prepend it to the second
^ Reverse the stack
≈[_\"pǏ] Execute if all elements are the same.
Since this is not the case, it just pops the third copy of the source code
₴ Print the source引用版本:("在网上试试!")
"`...`Dqp^≈[_\"pǏ]₴"
" Push the set [0, 0]
`...` Push the source code
D Make 3 copies of the source code
qp Uneval the first copy and prepend it to the second
^ Reverse the stack, putting [0, 0] on the top
≈[ ] Execute if all elements of the top of the stack are the same.
This is the case because of the [0, 0] pushed by "
_ Remove the third copy of the source from the stack
\" Push `"`
pǏ Prepend and enclose the source with `"`
₴ Print the source
" Push [0, 0], having no effect because the source is already printed发布于 2021-06-25 06:07:50
--"#p=p['"']>>"--\""#p
k#p=p x>>print x>>p k;main="--"#putStr;x="--\"#p=p['\"']>>\"--\\\"\"#p\nk#p=p x>>print x>>p k;main=\"--\"#putStr;x="
--"--"#p=p['"']>>"--\""#p
k#p=p x>>print x>>p k;main="--"#putStr;x="--\"#p=p['\"']>>\"--\\\"\"#p\nk#p=p x>>print x>>p k;main=\"--\"#putStr;x="
--"这使用了一种非常简单的检测方法。
第一行通常是注释。
--"#p=p['"']>>"--\""#p然而,当引号添加到前面时
"--"#p=p['"']>>"--\""#p它成为操作符(#)的声明。因此,该程序所做的是定义(#),以便在使用"--"#putStr调用时打印正常的源,但是当引号出现时,新的定义将取代它,并使用引号打印源。
https://codegolf.stackexchange.com/questions/108331
复制相似问题