50
\$\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
    Commented May 13, 2015 at 13:13
  • 1
    \$\begingroup\$ Also, do we have to print the first and the last lines which are simply spaces ? \$\endgroup\$
    – Optimizer
    Commented May 13, 2015 at 13:17
  • 2
    \$\begingroup\$ Inspired by this? \$\endgroup\$
    – Spikatrix
    Commented May 13, 2015 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
    Commented May 13, 2015 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\$ Commented May 13, 2015 at 23:24

45 Answers 45

1
2
1
\$\begingroup\$

Jelly, 15 bytes - 10 = 5 (non-competing?)

ḶṚ⁶ẋ;€⁹ZṄœS$€ṛ“

Try it online!

Sleeps for a second between each line. Prints a trailing newline, if that's acceptable.

yay Jelly beats Charcoal

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

PHP4.1, 85-10=75 bytes

Yes, this is a very old version, but it has a functionality I need.
You can still run it in any more recent versions of PHP, but you need to set the variables yourself before running the code below.

That helps me to reduce the size of my code a lot!

It is really basic:

<?for($s=str_repeat(' ',$n).$s;$i++<strlen($s)+$n;sleep(1))echo substr($s,$i,$n),'
';

I ran for the bonus due to this, quoting O.P.:

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.

As you can obviously see, it has a sleep.

This assumes that you have register_globals enabled by default, which were the default settings for this version.


You can easily test in your browser, with minimal some changes:

//detects if it is running in js or php
//true for js, false for php
if('\0'=="\0")
{
	function strlen($s){
		return $s.length;
	}
	
	function str_repeat($s,$n){
		return Array($n+1).join($s);
	}
	
	function substr($s,$n,$m){
		return $s.substr($n,$m);
	}
	
	function printf($s){
		document.write($s);
	}
	
	function concat($a,$b){
		return $a+$b;
	}
}
else
{
	function concat($a,$b){
		return $a.$b;
	}
}

//sets the variables, not required for PHP if you pass the values by GET or POST
$i=0;
$s='example';
$n=6;



for($s=concat(str_repeat('-',$n),$s);$i++<strlen($s)+$n;)printf(concat(substr($s,$i,$n),'<br>'));
*{font-family:monospace}

The above code is a polyglot and you can run in your browser or in a PHP interpreter. Shouldn't I get a prize for this? A cookie, perhaps?

List of changes:

  • Removed the sleep(1) in this test
  • Created 2 versions of the function concat
    The goal is to overcome PHP and JS differences in concatenating strings.
  • Instead of a space, a - is used to fill the space
  • Instead of echo, printf is uses instead (PHP limitation)
  • Instead or a 'real' newline, <br> is uses instead
\$\endgroup\$
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\$
    – Wheat Wizard
    Commented Jun 23, 2017 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\$

Charcoal, 7 bytes

FN«P↓η↗

Try it online!

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

Nibbles, 6.5 bytes (13 nibbles)

`'.\`,$:^$" "_

Transpose approach copied from The Thonnu's Thunno 2 answer.

    `,          # list of 0..
                #   arg1-1
   \            # reversed
  .             # map over this
       :        # append   
             _  # arg2 onto
        ^$      # that many
          " "   # spaces
`'              # and then transpose it all

enter image description here

\$\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\$
0
\$\begingroup\$

Vyxal L, 5 bytes

*/¹ɾ꘍

Try it Online!

Wow it's been way too long since I last used vertical join. Takes n then the string.

Explained

*/¹ɾ꘍­⁡​‎‎⁡⁠⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁤​‎‏​⁢⁠⁡‌­
*      # ‎⁡Repeat the string n times
 /     # ‎⁢And split into n chunks
  ¹ɾ꘍  # ‎⁣append [1, n] spaces to each chunk (pairwise vectorised)
# ‎⁤The L flag transposes then joins on newlines.
💎

Created with the help of Luminespire.

Now you're probably wondering why there's such a specific flag. Well that's because it's a shortcut for having § at the end of the program. § is a built-in that transposes then joins on newlines.

Now you're probably wondering why there's such a specific built-in. Well that's because back in 2020 when I first added it, apparently I thought it was a useful enough thing that it was worth adding.

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

Uiua, 13 bytes

⍉≡↻⇡:¤⊂⊙:▽,@ 

Try it!

Prepend N spaces to the input. For each 0..N rotate the string left that many characters, and transpose.

\$\endgroup\$
1
2

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.