11
\$\begingroup\$

Given a string of ASCII art like such (This isn't ASCII art but it will do for the example):

abc
d e
fgh

Jumble it as if it was being displayed on a screen with one character per line, like so:

a
b
c
d

e
f
g
h

Print the result, wait one second, ±0.5 seconds before clearing the terminal and the print the same thing, but with 2 characters displayed per line instead of 1. Basically, the width of the display turns from 1 to 2.

ab
c
d 
e
fg
h

Note the space after the d. Repeat waiting, then printing with an additional character per line until the inputted text is outputted.

If you hit the end of a line when trying to print characters, then you insert a newline and print the rest of them following this rule. For example the input:

abcdefg
ab

Would print the following when the display length is 4.

abcd
efg
ab

You can find the effect of the terminal resize here: https://repl.it/GoeU/1. Run the program, then drag the thing separating the terminal from the text editor back and forth.

Clarification:

Once a line appears exactly how it was inputted, you can leave that line alone for future larger character counts per line.

abc
ab

should print

ab
c
ab

when the sentence length = 2.


This is , so least amount of bytes wins!

Rules:

  • Must print to STDOUT as the only output.
  • Must clear the terminal, or create the illusion of clearing the terminal by adding 150 or so empty lines.
  • Can take input through the standard methods.
  • Default loopholes apply.
  • Trailing stuff with the text is NOT OKAY.

This idea came to me when I was resizing a terminal with ASCII art on it. It looked interesting, so I decided to make a challenge out of it.


Test cases:

Since it would be too much work to show each step for each test case individually, I will review each answer to make sure it is valid. Make sure the answer can handle the test cases.

 ______   ______     __     __   __     ______      __    __     ______    
/\  == \ /\  == \   /\ \   /\ "-.\ \   /\__  _\    /\ "-./  \   /\  ___\   
\ \  _-/ \ \  __<   \ \ \  \ \ \-.  \  \/_/\ \/    \ \ \-./\ \  \ \  __\   
 \ \_\    \ \_\ \_\  \ \_\  \ \_\\"\_\    \ \_\     \ \_\ \ \_\  \ \_____\ 
  \/_/     \/_/ /_/   \/_/   \/_/ \/_/     \/_/      \/_/  \/_/   \/_____/ 

This pastebin.

                        __/\__
                        \    /
                  __/\__/    \__/\__
                  \                /
                  /_              _\
                    \            /
      __/\__      __/            \__      __/\__
      \    /      \                /      \    /
__/\__/    \__/\__/                \__/\__/    \__/\__
\$\endgroup\$

3 Answers 3

3
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ This ones way better and shorter than mine. Great job! (y) \$\endgroup\$
    – 0xffcourse
    Commented Apr 2, 2017 at 2:55
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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)
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Cool! I think you could shave off some bytes by using the code z=print at the top, and then changing all other instances of print() to z(). \$\endgroup\$
    – sporkl
    Commented Apr 1, 2017 at 13:09
  • 1
    \$\begingroup\$ I think you cold do the same thing you did with print with range, and instead of range(0,3) use range(3). \$\endgroup\$
    – sporkl
    Commented Apr 1, 2017 at 17:05
  • 1
    \$\begingroup\$ sleep(0.5) can be rewritten as merely sleep(.5) \$\endgroup\$
    – steve
    Commented Apr 1, 2017 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.