Pushy, 20 17 16 or 13 bytes
Not a very elegant solution..Depending on what's allowed, there are two solutions.
16 bytes:
% 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 bytes:
While coding the above answer I came up with this significantly shorter solution:
N@$L1TU&Wm:'.
Although it does a similar thing, it prints directly off the string rather than constructing a new string, for fewer bytes. This requires the N
at the beginning of the program to prevent trailing newlines, or else each character would be on a newline.
However, whilst testing this I noticed a bug - stdout
is line-buffered, so the program would wait the full length, and then display the hiccuped string.
I've fixed this in the latest commit by adding a simple .flush()
- this is technically not adding a new feature to the language, just fixing a bug, but I understand if you don't take this answer into account :)
The breakdown looks like this:
% 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:
'. % Print & Pop last char