Create an ASCII art unjumble!
Python 3.6, 124 bytes
Loops over length of input string like officialaimm's solution
import re,time
def d(s):
for i in range(len(s)):print(*'\n'*75,*re.split(f'(.{{1,{i+1}}})',s)[1::2],sep='\n');time.sleep(1)
143 bytes to only go to width of longest line a al Frxstrem's Bash answer
import re,time
def d(s):
for i in range(max(map(len,s.split()))):print(*'\n'*75,*re.split(f'(.{{1,{i+1}}})', s)[1::2],sep='\n');time.sleep(.5)
Uses "re.split((.{1,i+1}))" to break the string into groups of characters. Because '.' doesn't match '\n', the groups don't wrap around from one line to the next. If the regex uses a capturing group, then re.split() returns a list with the matched groups at the odd indexes. These are retrieved with [1::2].
Uses python 3.6 f-string to make the re pattern depend on group width i.
The * in front of re.split() uses python 3.6 unpacking to turn the list into arguments to the print statement. Similarly, *'\n'*75, turns into 75 '\n' arguments to the print statement. With the print keyword argument sep='\n', the result is printing about 150 blank lines to clear the screen, followed by each group of characters on a separate line.
Python 3.5 (238 233 229 225 223 222 bytes)
- Works fine in the windows terminal; not sure about other platforms, because of the system-specific os.system("cls") command.
- The string passed should be marked by \n for newlines eg: 'abc\nd efgh\n'
import os,time
def b(s):
p=len(s);z=print;r=range
for i in r(1,p):
os.system("cls");l=0
for j in r(p):
z(s[j],end="");l+=1
if(s[j]=='\n'):l=0
if(j+1<p and l==i and s[j+1]!='\n'):z();l=0
z();time.sleep(.5)
- Saved 5 bytes: removed unwanted whitespaces
- Saved 4 bytes: shorthand for len(s)
- Saved 4 bytes: Thanks to sparklepony (shorthand for print)
- saved 2 bytes: Thanks to sparklepony (shorthand for range as r and r(0,i) as range(i))
- saved 1 byte: Thanks to steve (0.5 as just .5)
Bash (with GNU coreutils), 69 bytes
n=`tee x|wc -L`;for i in `seq 1 $n`;do fold -w$i x;sleep 1;clear;done
Saves input in temporary file x
, then counts the longest line (GNU coreutils' wc
has -L
flag for this) and iterates for each console width from 1 to the longest line length. fold
, sleep
and clear
does the rest of the magic.