Print invisible text

Given a string as input, output a number of whitespace characters (0x0A and 0x20) equal to the length of the string.

For example, given the string Hello, World! your code would need to output exactly 13 whitespace characters and nothing else. These can be any mix of spaces and newlines.

Testcases:

     Input      -> Amount of whitespace to output
"Hello, World!" -> 13
"Hi"            -> 2
"   Don't
Existing
Whitespace!   " -> 45
""              -> 0
"             " -> 13
"
"               -> 1


Scoring:

This is so fewest bytes wins!

• I don't get what you mean with that “0x0A”. Where should that be output? Should that be kept, so “a␠b␊c” becomes “␠␠␠␊␠”? – manatwork May 25 '17 at 12:56
• @manatwork 0x0A and 0x20 are the hexadecimal values for the Newline and Space characters respectively – Skidsdev May 25 '17 at 12:58
• “output a number of whitespace characters (0x0A and 0x20)” – Where in the output should those newline characters be? – manatwork May 25 '17 at 13:00
• These can be any mix of spaces and newlines Your output can be any mix of spaces and newlines, you can just output spaces if you want, like everyone else, or you can just output newlines. It's up to you – Skidsdev May 25 '17 at 13:05
• Got it. Thanks. – manatwork May 25 '17 at 13:06

Flurry-bnb, 42 bytes

[]{(){}{}}[]{({})}<((({<({}){}>})){}){}{}>


Try it online!

$printf "Hello World!" | ./flurry -bnb a.flr$ printf "Hello World!" | ./flurry -bnb a.flr | wc -c
12


It takes 24 bytes just to construct a single space (32): <((({<({}){}>})){}){}{}>. Even worse is that it takes 2 more byets to construct a single newline (10): (<><<>()>)<(<({}){}>{}){}>...

The algorithm is: empty the stack, preserving the value of stack height, and then push space that many times.

main = height pop-I height push-I 32

// Return self, popping and discarding one item from stack
pop-I = \x. K x pop
// (height pop-I height) returns original stack height with
// the stack emptied as a side effect

// Return self, pushing itself to the stack once
push-I = \x. push x

32 = 2**2 * 2**2 * 2
= <(2 2)(2 2)2>
= <(push ((push (push 2)) pop)) pop pop>


Rockstar, 27 bytes

listen to S
cut S
say " "*S


Try it here (Code will need to be pasted in)

Replace the last line with the below to wrap the output in single quotes.

say "'"+" "*S+"'"


Husk, 4 bytes

R' L


Try it online! (Note: prints xs instead of spaces so that the output is visible; change the x to   to [not] see the real version)

Nim, 38 bytes

for _ in stdin.readAll:stdout.write" "


Try it online!

Since Nim is style-insensitive, something like this also works:

fOr _ iN sTdIn.rEaDaLl:sTdOuT.wRiTe" "


Try it online!

05AB1E, 3 bytes

gð×


Try it online!

gð×  # full program
ð   # a space...
×  # repeated...
g    # length of input...
×  # times

• ...nice, but quite similar to this... – Dominic van Essen Nov 17 '20 at 18:06

REXX 27 Bytes

say left("",length(arg(1)))


ZX80 (4K ROM version with sanity check)

~58 bytes (listing)

 1 INPUT A$2 IF A$="" THEN GO TO 1
3 PRINT " ";
4 LET A$=TL$(A$) 5 IF A$="" THEN STOP
6 GO TO 3


Line 2 can be removed to save RAMs. However, if an empty string is entered without line 2 then it will PRINT one space.

• It is now later. – CalculatorFeline May 26 '17 at 3:08

TXR Lisp, 22 19 bytes:

(op regsub #/./" ")


Previously:

(op mapcar(ret[" "0]))


That is a function to which we can pass a string:

REPL:

1> (op regsub #/./" ")
#<interpreted fun: lambda #:rest-0164>
2> [*1 "abc"]
"   "

"   "


Clojurescript, 27 bytes

#(apply str(map(fn[]" ")%))


Because it's based on js, clojurescript doesn't care about arity errors. That saves one byte over the clojure eqivalent.

Windows batch, 115 bytes

@set i=%~1
@set p=0
@set/ac=-1
:N
@call set t=%%i:~%p%,1%%
@set/ac+=1
@set/ap+=1
@if "%t%" NEQ "" @goto N
@echo %c%


Re-used code from my answer in Is the checkbox not not unchecked?

Bash + Coreutils, 11 Bytes

tr -c \ \

Powershell, 22 Bytes

' '*(Read-Host).length

• Not sure if Read-Host counts for input but " "*"$args".length is shorter anyway. Also there is not len property. That should be printing nulls. – Matt May 30 '17 at 12:17 • Length property and Len are same – Sivaprasath Vadivel May 30 '17 at 13:32 • "hello".Len is null on my system because that is a non-existent property where as "hello".Length returns 5. If that works for you then you have an alias or extent that I, and most, do not have. – Matt May 30 '17 at 14:14 • Ok...That explains it – Sivaprasath Vadivel May 30 '17 at 14:15 Ruby, 12 11+1 = 13 12 bytes Uses the -p flag. -1 byte from Martin Ender. gsub /./,$/


Try it online!

J, 6 bytes

' '#~#


Try it online!

Explanation

' '#~#
#~    repeat
' '      spaces
#   for length of input

• 4 bytes ''"0 outputs n newlines. – FrownyFrog Oct 28 '17 at 1:07
• @FrownyFrog You should make your own answer, it's quite different from mine – Conor O'Brien Oct 28 '17 at 3:51

Common Lisp, 32 bytes

(format t"~va"(length(read))#\ )


Try it online!

Carrot, 12 bytes

#^//()/gS" "


Try it online! (append a ^@^v@ after the code to see the spaces bounded between @s)

Explanation

#^            Set the stack-string to be equal to the input
/             Get matches of this regex
/()/g         any position (not character) in the string (shorter than /\b|\B/ by 3 bytes)
If the length of the string is 3, this returns a 4-element array
consisting of empty strings
S" "          Join on spaces, so the example 4-element array will result in 3 spaces


The space can even be replaced with a literal newline or tab for the same bytecount.

Befunge-98 (PyFunge), 5 bytes

#@~a,


Try it online!

For every character in the input (#@~), this prints a new line (a,).

dc, 18 bytes

?Zd[9P1-d0<r]sr0<r


Try it online!

RProgN 2, 3 bytes

L•*


Uncreative solution is uncreative.

Just gets the length of the input, and multiplies •, which is predefined to be a space, by it.

Try it online!

Ly, 9 bytes

iy[' o,];


Try it online!

Explanation:

iy[' o,];

iy        # push length of input
[    ]  # while loop
' o    # output a space
,   # decrement input length
; # terminate (avoids implicit output)


def L:length;$x|if L<1then empty elif L<2then""else L-1|.*" "end  This is longer then usual to compensate for newline jq normally emits and the odd behavior of * with N<2 Sample runs: $ jq -Mrn --arg x 'Hello, World!' 'def L:length;$x|if L<1then empty elif L<2then""else L-1|.*" "end'$ jq -Mrn --arg x 'Hello, World!' 'def L:length;$x|if L<1then empty elif L<2then""else L-1|.*" "end' | wc -c 13$ echo -n 'def L:length;$x|if L<1then empty elif L<2then""else L-1|.*" "end' | wc -c 64  Shout out to Jonathan Frech for finding 3 superfluous spaces! • I do not know jq, but as then""else is syntactically valid, it seems like you could also omit the space in " " end. – Jonathan Frech Sep 19 '17 at 7:07 • As variables probably cannot begin with a digit, the spaces in <1 then and <2 then may also be superfluous. – Jonathan Frech Sep 19 '17 at 7:40 Vim, 4 bytes VGr  (a trailing space) Julia 0.6, 15 bytes s->" "^endof(s)  Try it online! ^ applied to strings is the repetition operator, and endof gives the last index of the string, which is equal to the length of the string (since Julia indexing is 1-based). Yabasic, 37 bytes Takes input, and outputs as many new lines as the length of the input Line Input""s$
For i=1TO Len(s$)?Next  Try it online! C# .NET, 84 bytes class P{static void Main(string[]a){System.Console.Write("".PadLeft(a[0].Length));}}  Try Online Kotlin, 20 bytes {" ".repeat(length)} {" ".repeat // repeat space (length)} // length of input  Try it online! Vyxal, 4 bytes L\ *  Command-line usage: python3 Vyxal.py file_name "" input_string  Explained L # Push the length of the implicit input \ # Push a space character * # Multiply that space by the length and output.  Forth (gforth), 9 bytes typewhite  Try it online! It is a gforth built-in. A string in gforth is commonly represented as addr length, and typewhite consumes addr length and prints length spaces. • forth golfing language confirmed?! – Razetime Nov 17 '20 at 15:33 Add++, 21 bytes D,f,@@,bL*$f>" ">?
o


Try it online!

Check, 6 bytes

," "*o


Pass the input by the command-line arguments as a list of code points, i.e. [72,101,108,108,111,44,32,87,111,114,108,100,33].

Explanation:

• , gets the length of the input.
• " " pushes an array containing 32 (for space).
• * repeats that array as many times as the length of the input.
• o displays the result as a list of characters.