Fake Marquee Text
CJam, 12 11 bytes
1 byte saved by Dennis.
,Sf*\f+$zN*
I'm making use of "Input can be hard-coded but easy to change": this expects the input to be already on the stack, so you can prepend "testing" 4
to the above, for instance.
Test it here.
Explanation
Notice that the transpose of the desired output is much simpler:
testing
testing
testing
testing
So we just need to create n
lines, prepending i
spaces for i
from n-1
down to 0
. That's what the code does:
, e# Turn n into a range [0 1 .. n-1]
Sf* e# Turn each i into a string of i spaces.
\f+ e# Swap this array with the input string and append it to each of the
e# strings of spaces.
$ e# Sort the array to have the string with n-1 spaces first.
z e# Transpose the grid.
N* e# Join the lines with newline characters.
19 - 10 = 9?
I find the "sleeps a bit between each line" bonus a bit vague and dodgy, but here is a 19 byte version that simply stalls after each line by computing all permutations of the array [0 1 .. 7]
. In the online interpreter this simply leads to the final result being shown a bit later, but if you use the Java interpreter this will actually print each line after "sleeping a bit":
,Sf*\f+$z{oNo8e!;}/
C, 69 bytes
printf magic!
f(s,n,i)char*s;{for(i=n;*s;i?i--:s++)printf("%*s%.*s\n",i,"",n-i,s);}
Expanded version with some explanation:
f(s,n,i)char*s;{ /* s is the string, n is the width of the grid. */
for(i=n; /* i is the number of preceding spaces. */
*s; /* Stop once we reach the end of the string. */
i?i--:s++) /* Decrease the number of spaces, and when there's
none left start truncating the string itself. */
printf("%*s /* The first argument is the minimum width to print the
string (left padded with spaces) and the second
argument is the string to print. We use the empty
string just to print the i spaces. */
%.*s /* The third argument is the maximum number of
characters from the string (which is the fourth
argument) to print. */
\n",i,"",n-i,s);
}
And here's an example:
$ ./marquee stackoverflow 12 s st sta stac stack stacko stackov stackove stackover stackoverf stackoverfl stackoverflo tackoverflow ackoverflow ckoverflow koverflow overflow verflow erflow rflow flow low ow w
Pyth, 13 bytes
jb.:++K*dQzKQ
Try it online: Pyth Compiler/Executor
Explanation
implicit: z = input string, Q = input number
K*dQ K = " " * Q
++K zK K + z + K
.: Q all substrings of length Q
jb join by newlines and print