Pushy,20 17 16或13个字节
根据所允许的内容,有两种解决方案。
16个字节:
@$LT1U&Wm:v;O"cI
在命令行上输入参数:$ pushy hiccup.pshy 'hiccupinator'
。每次“打h”后,该行将打印尾随换行符。细目如下:
% Implicit: input on stack as charcodes
@ % Reverse input, so chars are pulled from start
$ I % While there are items on stack:
T1U % Push a random number, 1-10
&W % Wait that many seconds
L m: % min(time waited, chars left) times do:
v; % Pull a char from the input.
O"c % Print & delete pulled chars
13个字节:
在对以上答案进行编码时,我想出了这个明显更短的解决方案:
N@$L1TU&Wm:'.
尽管它做了类似的事情,但是它直接从字符串上打印出来,而不是构造一个更少的字节的新字符串。这需要N
在程序开始时使用来防止尾随换行符,否则每个字符都会在换行符上。
但是,在测试时,我发现了一个错误- stdout
行缓冲,因此程序将等待整个长度,然后显示打string的字符串。
我已经在最新的提交中修复了这个问题通过添加一个简单的方法.flush()
-从技术上讲,这不是在语言中添加任何新功能,只是修复了一个错误,但是我知道您是否不考虑这个答案:)
细目如下:
% Implicit: input on stack as charcodes
N % Set trailing newlines to False
@ % Reverse stack (so the charcodes are pulled off in order)
$ % While there are items left to print:
L % Push stack length
1TU % Push a random number 1-10
&W % Wait that amount of time
m: % min(time waited, chars left) times do:
'. % Pop and print last char