``您的任务是编写一个程序或函数,每次运行时输出其源代码的第一个字符,然后输出第二个字符,然后输出第三个字符。
例如,如果您的程序使用file foo中的语言,那么您应该获得类似于以下内容的输出:barbaz.bar
λ bar baz.bar
f
λ bar baz.bar
o
λ bar baz.bar
o
程序以这种方式打印源代码后,便可以执行任何操作。您可以修改文件的源代码,但是请记住,要打印的源代码是原始源代码。
这是一个代码高尔夫球,因此以字节为单位的最短程序获胜。
``您的任务是编写一个程序或函数,每次运行时输出其源代码的第一个字符,然后输出第二个字符,然后输出第三个字符。
例如,如果您的程序使用file foo中的语言,那么您应该获得类似于以下内容的输出:barbaz.bar
λ bar baz.bar
f
λ bar baz.bar
o
λ bar baz.bar
o
程序以这种方式打印源代码后,便可以执行任何操作。您可以修改文件的源代码,但是请记住,要打印的源代码是原始源代码。
这是一个代码高尔夫球,因此以字节为单位的最短程序获胜。
Answers:
“;⁾vṾ®ȯ©Ḣ”vṾ
这是一个尼拉迪亚链接。在线尝试!(包括用于十二次调用链接的代码。)
“;⁾vṾ®ȯ©Ḣ”vṾ Niladic link.
“;⁾vṾ®ȯ©Ḣ” Set the left argument and the return value to s =: ';⁾vṾ®ȯ©Ḣ'.
Ṿ Uneval; yield r =: '“;⁾vṾ®ȯ©Ḣ”', a string representation of s.
v Eval; execute s as a Jelly program with argument r.
⁾vV Yield 'vṾ'.
; Concatenate r and 'vṾ', yielding q =: '“;⁾vṾ®ȯ©Ḣ”vṾ'.
®ȯ Take the flat logical OR of the register (initially 0) and q.
This replaces 0 with q in the first run, but it will yield the
content of the register in subsequent runs.
© Copy the result to the register.
Ḣ Head; pop and yield the first character of the register.
This modifies the string in the register, so it holds one fewer
character after each call.
另外,由于寄存器在第十二次调用后将保留一个空字符串,因此它再次处于错误状态,并且链接已准备好从头开始。调用链接24次将输出两次源代码,调用三次三次,等等。
¢),标识函数(¹,在第一次调用后并不需要),将返回值设置为换行符(⁷,隐式打印先前的返回值),然后重复。¹并且⁷都是上标,但它们是无关的。我已将它们替换为不太混乱¢;¢;¢;¢;¢;¢;¢;¢;¢;¢;¢;¢(调用,连接,重复)。
定义f()一个字符一个字符地返回源代码。
n=0;f=x=>("n=0;f="+f)[n++]
字符用完后返回undefined。
n=0;f=x=>("n=0;f="+f)[n++]
for(i=0;i<30;i++){console.log(f())} //test harness
{Y"{Y (yRsRPy++v)}"(yRsRPy++v)}
匿名函数。在TIO上测试!
从这个标准的Pip quine开始:
Y"Y yRsRPy"yRsRPy
Y"Y yRsRPy" Yank that string into y
yRsRPy In y, replace the space with repr(y)
将其括在花括号中以使其起作用。现在,我们无需返回整个源,而是需要对其进行索引。对索引使用全局变量并在每次递增时,将满足“每次调用时下一个字符”的要求。v是最佳候选者,因为它已预初始化为-1。第一次增加它的索引为0,下一次1等等。
Pip具有循环索引,因此一旦函数打印出最后一个字符,它将从头开始。
标准Python quine的扩展(欢迎打高尔夫球的技巧):
def f(n=0,s='def f(n=0,s=%r):\n while 1:yield(s%%s)[n];n+=1'):
while 1:yield(s%s)[n];n+=1
这是一个python 生成器函数,意味着您对其进行迭代,并且每次迭代都会在源代码中提供下一个字符。返回所有字符后,将崩溃IndexError。
为了进行测试,只需将此脚本附加到程序的末尾:
source = ''
try:
# Call generator, add characters to the string
for char in f():
source += char
except IndexError:
# Generator has reached end of source code
pass
print(source)
" r:2+a1Fi1+:1F1+[ro;
创建一个名称\n为跟踪索引的文件。
这也许可以打更多的球,但是没有什么立即跳出来……
$ starfish incrementalquine.sf
"$ starfish incrementalquine.sf
$ starfish incrementalquine.sf
r$ starfish incrementalquine.sf
:$ starfish incrementalquine.sf
2$ starfish incrementalquine.sf
+$ starfish incrementalquine.sf
a$ starfish incrementalquine.sf
1$ starfish incrementalquine.sf
F$ starfish incrementalquine.sf
i$ starfish incrementalquine.sf
1$ starfish incrementalquine.sf
+$ starfish incrementalquine.sf
:$ starfish incrementalquine.sf
1$ starfish incrementalquine.sf
F$ starfish incrementalquine.sf
1$ starfish incrementalquine.sf
+$ starfish incrementalquine.sf
[$ starfish incrementalquine.sf
r$ starfish incrementalquine.sf
o$ starfish incrementalquine.sf
;$ starfish incrementalquine.sf
" r:2+ build the quine
a1F open file named "\n"
i1+: read input, increment by 1, duplicate
1F save incremented input to file
1+[ increment input, copy that many values to a new stack
ro output the character at the beginning of the new stack
; end
a1Fi1+:0go1F;
说明
a1F open file named "\n"
i1+ read input and add 1 to it
:0g push the value at (input,0) to the stack
o output the value
1F save the incremented input to the file
; exit
g指令读取源代码。
"your code goes here;用于> <>,然后访问堆栈中的第n个成员
评论非常欢迎;我仍在学习有关什么是适当的奎因的提法。
(If[!NumberQ[q], q = 0]; StringTake[ToString[#0]<>FromCharacterCode[{91, 93}], {++q}]) & []
定义一个不带参数重复调用的函数。在第91次调用之后,它将引发一个大错误并返回未评估的值。
有两个需要解决的问题:首先,我只想使用StringTake[ToString[#0]<>"[]"],但是ToString[]似乎删除了引号。所以我不得不更换"[]"的FromCharacterCode[{91, 93}]。第二,Mathematica变量开始时未初始化,因此++q在q定义之前我无法调用;这就是为什么If[!NumberQ[q], q = 0]需要缩写的原因。
无关的尾声:在查找时NumberQ,我了解到Mathematica具有一个称为TrueQ... 的函数,是的,True如果参数为,True并且参数为,False则返回False!(该实用程序还返回False所有其他参数。)