首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >报价-安全奎因

问报价-安全奎因
EN

Code Golf用户
提问于 2017-01-27 05:03:17
回答 2查看 1.2K关注 0票数 25

您的任务很简单:编写一个不需要输入和输出(或返回)源代码的程序(或函数)。问题是,当程序用"quotes" (Unicode字符34)包装时,它应该再次输出它的(现在引用的)源代码。

适用奎因的标准规则。这是密码-高尔夫,所以最短的程序(以字节为单位)获胜。

EN

回答 2

Code Golf用户

发布于 2021-06-02 00:31:15

维沙尔 D,29字节

代码语言:javascript
复制
`Dqp^≈[_\\"pǏ]₴`Dqp^≈[_\"pǏ]₴

在网上试试!

解释:

代码语言:javascript
复制
`...`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

引用版本:("在网上试试!")

代码语言:javascript
复制
"`...`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
票数 2
EN

Code Golf用户

发布于 2021-06-25 06:07:50

哈斯克尔,142个字节

代码语言:javascript
复制
--"#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="
--

在网上试试!

代码语言:javascript
复制
"--"#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="
--"

在网上试试!

这使用了一种非常简单的检测方法。

第一行通常是注释。

代码语言:javascript
复制
--"#p=p['"']>>"--\""#p

然而,当引号添加到前面时

代码语言:javascript
复制
"--"#p=p['"']>>"--\""#p

它成为操作符(#)的声明。因此,该程序所做的是定义(#),以便在使用"--"#putStr调用时打印正常的源,但是当引号出现时,新的定义将取代它,并使用引号打印源。

票数 2
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/108331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档