47
\$\begingroup\$

In this challenge fake marquee text is text that is shown part by part, in a scrolling-like fashion.

Some examples:

testing 4

   t
  te
 tes
test
esti
stin
ting
ing
ng
g


hello 2

 h
he
el
ll
lo
o


foobarz 3

  f
 fo
foo
oob
oba
bar
arz
rz
z


Something a bit longer 10

         S
        So
       Som
      Some
     Somet
    Someth
   Somethi
  Somethin
 Something
Something 
omething a
mething a 
ething a b
thing a bi
hing a bit
ing a bit 
ng a bit l
g a bit lo
 a bit lon
a bit long
 bit longe
bit longer
it longer
t longer
 longer
longer
onger
nger
ger
er
r


small 15

              s
             sm
            sma
           smal
          small
         small
        small
       small
      small
     small
    small
   small
  small
 small
small
mall
all
ll
l


aaa 3

  a
 aa
aaa
aa
a


brace yourself 6

     b
    br
   bra
  brac
 brace
brace 
race y
ace yo
ce you
e your
 yours
yourse
oursel
urself
rself
self
elf
lf
f

You have to write a program or a function that takes in two input and prints the output as described above. You may or may not output trailing spaces in your output. This is code-golf so shortest code in bytes wins.

If your program is standalone (i.e. when run actually prints the lines) (Input can be hard-coded but easy to change) and sleeps a bit between each line of output you get a -10 bonus.

\$\endgroup\$
16
  • \$\begingroup\$ What do you mean by "includes Output" ? \$\endgroup\$
    – Optimizer
    May 13 '15 at 13:13
  • 1
    \$\begingroup\$ Also, do we have to print the first and the last lines which are simply spaces ? \$\endgroup\$
    – Optimizer
    May 13 '15 at 13:17
  • 2
    \$\begingroup\$ Inspired by this? \$\endgroup\$
    – Spikatrix
    May 13 '15 at 14:18
  • 1
    \$\begingroup\$ A single empty line at the beginning seems to be allowed. How about another empty line at the end? \$\endgroup\$
    – nimi
    May 13 '15 at 17:57
  • 2
    \$\begingroup\$ Since you're talking about "only visible output", can we assume that the input will only be printable ASCII? (character codes 0x20 to 0x7E) \$\endgroup\$ May 13 '15 at 23:24

41 Answers 41

1
2
1
\$\begingroup\$

APL (Dyalog), 17 bytes

⌽⍉↑(⎕,⍨' '/⍨⊢)¨⍳⎕

Try it online!

(the program assumes ⎕IO←0 which is default on many machines)

Explanation

⍳⎕               Create a range 0 .. input-1
¨                For each element in this range do:
 ' '/⍨⊢           A space duplicated right argument (which is the element in  the range) times
 ⎕,⍨              Concatenated with the input string to its right
⌽⍉               Transpose and reflect horizontally
\$\endgroup\$
1
\$\begingroup\$

Python 3, 62 bytes

Definitely think it can be golfed further, particularly with the for loop notation.

Unfortunately I'm not that fluent with Python yet, maybe someone here can help.

def f(s,n):
 s=n*" "+s
 for i in range(len(s)):print(s[i:i+n])

Try it online!

I hope leading spaces are allowed.

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to site! \$\endgroup\$
    – Grain Ghost
    Jun 23 '17 at 14:55
1
\$\begingroup\$

PowerShell, 60 bytes

param($s,$n)($t=' '*--$n+$s)|% t*y|%{-join$t[$i..($i+++$n)]}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Japt -R, 7 bytes

VÆiYîÃz

Run it online

\$\endgroup\$
1
\$\begingroup\$

Canvas, 3 bytes

*/⤢

Try it here!

Input is string and integer (in either order) separated by a newline.


Explanation:

*     | Repeat a b times vertically (a=string input, b=int input) 
  /   | Make antidiagonal (add one extra space to each line bottom up)
    ⤢ | Transpose (reflect along top-left to bottom-right diagonal)
\$\endgroup\$
0
\$\begingroup\$

Charcoal, 7 bytes (non-competing?)

FN«P↓η↗

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Google Sheets, 79 bytes

=ARRAYFORMULA(JOIN("
",MID(REPT(" ",A2)&A1,ROW(OFFSET(A2,0,0,LEN(A1)+A2)),A2)))

Text is input in cell A1 and the marquee width is in cell A2.
ARRARYFORMULA + ROW(OFFSET()) lets us return multiple values into the MID function.
After that, all we do is return A2 characters from the middle of the text prepended with spaces as needed.
JOIN combines them all with a line break in between each.

Sample outputs:

Sample Outputs

I expected this challenge to require clearing the screen so it looks like a marquee in place but, as it (currently) doesn't, I think this answer is valid.

\$\endgroup\$
0
\$\begingroup\$

T-SQL, 110 bytes

DECLARE @n INT,@ CHAR(99)SELECT @n=n,@=space(@n)+s FROM t
L:SET @=RIGHT(@,98)PRINT LEFT(@,@n)IF LEN(@)>0GOTO L

Input is via pre-existing table t with columns n (INT) and s (CHAR), per our IO standards.

Formatted:

DECLARE @n INT, @ CHAR(99)
SELECT @n=n, @=space(@n)+s FROM t
L:
    SET @=RIGHT(@,98)
    PRINT LEFT(@,@n)
IF LEN(@)>0 GOTO L

The question didn't specify the range of values my code had to handle; it works for all given samples, but will cut off the text if n + len(s) exceeds 99. To handle huge values of n and much longer strings without cutting off, add two bytes by changing 99 to 999 and 98 to 998.

\$\endgroup\$
0
\$\begingroup\$

Perl 5, 43

53 bytes - 10 bonus

push@F,($")x($t=<>);sleep say@F[$_-$t..$_-1]for 1..@F

Try it online!

\$\endgroup\$
0
\$\begingroup\$

GolfScript, 20 bytes

~.' '*@+{.2$<p(;.}do

Try it online!

It prints the length at the end, due to it still being on the stack and implicit printing. I like to think of it as a feature, sort of like its a spelling bee ;)

Really taking the "input can be hardcoded but easy to change" to heart, I managed to get it down to only 17 bytes:

' '*\+{.b<p(;.}do

Try it online!

Input is appended to the stack, in addition to the size being stored in a variable. The main issue was organizing the stack because the length is needed once to create a string of spaces, then it is also needed every loop cycle in order to truncate the string to the correct length. This adds 1 char for duplicating it, one to rotate the stack, and another to duplicate the length every loop cycle.

\$\endgroup\$
0
\$\begingroup\$

Zsh, 42 bytes

s=${(l:$2:)}$1;eval '<<<${s:'{1..$#s}:$2\}

Try it online!

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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