若要“函数嵌套”字符串,必须:
Hello,那么第一步是: H(ello)您的任务是编写“函数嵌套”字符串的程序或函数。例如,如果输入字符串是Hello world!,那么您应该输出:
H(e(l(l(o( (w(o(r(l(d(!)))))))))))输入将永远只包含可打印ASCII,您可以以任何合理的格式接受输入和输出。例如,STDIN/STDOUT、函数参数和返回值、读取和写入文件等。
为了简单起见,您还可以假设输入不包含括号,也不会是空的。
Input:
Nest a string
Output:
N(e(s(t( (a( (s(t(r(i(n(g))))))))))))
Input:
foobar
Output:
f(o(o(b(a(r)))))
Input:
1234567890
Output:
1(2(3(4(5(6(7(8(9(0)))))))))
Input:
code-golf
Output:
c(o(d(e(-(g(o(l(f))))))))
Input:
a
Output:
a
Input:
42
Output:
4(2)和往常一样,我们所有的默认规则和漏洞都适用,最短的答案(以字节为单位)获胜!
发布于 2016-10-18 20:31:38
0000 fc be 82 00 b4 02 ac 88 c2 cd 21 ac 3c 0d 74 0d
0010 b2 28 50 cd 21 5a e8 f0 ff b2 29 cd 21 c3使用命令行将字符串传递给可执行文件。( .COM文件名和字符串之间有一个空格字符)。
结果被写入标准输出。
拆卸在这里:
fc cld ; Make sure DF is not set (lodsb!)
be 82 00 mov si,0x82 ; First character of command line args
b4 02 mov ah,0x2 ; AH=2 means output for INT 21h
ac lodsb ; Load first character
88 c2 mov dl,al ; Move AL to DL (DL is written to output)
recursiveFunction:
cd 21 int 0x21 ; Output
ac lodsb ; Get the next character
3c 0d cmp al,0xd ; If it is "CR" (end of command line) ...
74 0d je doReturn ; ... return from the recursive function
b2 28 mov dl,0x28 ; Output "(" next...
50 push ax ; ... but save character read first
cd 21 int 0x21 ; (Actual output)
5a pop dx ; Restore character (but in DL, not in AL)
e8 f0 ff call recursiveFunction ; Recursively enter the function
doReturn:
b2 29 mov dl,0x29 ; Output ")"
cd 21 int 0x21
c3 ret ; Actually return注意:您可以使用"RET“指令退出DOS .COM文件(与带有EXE头的文件不同)。
发布于 2016-10-18 19:08:58
S'(ý¹g<')×J在网上试试!
S'(ý join input by "("
¹g< push length of input - 1, call it n
')× push a string with char ")" n times
J concatenate发布于 2016-10-18 19:02:40
>+++++[-<++++++++>],.,[<.>.>+<,]<+>>[-<<.>>]每次读取一个字节,在除第一个字节之外的每一个字节之前放置一个打开的paren,在末尾放置相同数量的关闭parens。
https://codegolf.stackexchange.com/questions/96641
复制相似问题