# 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

# SmileBASIC 3, 22 bytes

Asks for a string from the console as input, then prints length spaces. PRINT (or ? here) adds a trailing newline by default, so we use the ; to disable it.

LINPUT A$?" "*LEN(A$);

• This technically isn't valid since LINPUT doesn't accept newlines, so you'll have to define a function (also ; isn't required because PRINT doesn't really output newlines) – 12Me21 Mar 3 '18 at 16:18

## Mathematica, 30 bytes

Row@Table[" ",StringLength@#]&


# Lua, 25 bytes

for i=1,#...do
print()end


Same length as:

io.write((' '):rep(#...))


Try it online!

# tcl, 19

regsub -all . $s \  demo To test it, click "Run it" button and then select the white space on the white bottom area. A better test is to add a space and a letter before the ] as I describe: puts [regsub -all .$s \  x]
^^ Two spaces here


and it will output the count of characters of each string exactly equal to the ones on the question.

# Rust, 23 bytes

|s|" ".repeat(s.len());


First time using Rust so not 100% sure I've got everything correct, let me know if I need to change anything. I couldn't work out how to test this, as I'm still new to it, but judging from the documentation it should work. Also any improvements are more than welcome!

• Hi fellow newbie! I tried to rig up enough surrounding code to make a Try It Online link for this answer (and any similar Rust entries). I did get somewhere but I needed to add a type declaration at the cost of an extra 5 bytes (for a total of 28 bytes) to get it to compile. – RJHunter May 26 '17 at 3:48

# Brain-Flak, 28 bytes

{{}<>((()()()()()){})<>}<>{}


Try it online!

{{}                    }     # For every input character...
((()()()()()){})        #    Push 10...
<>                <>      #    on the other stack
<>   # Switch to the stack with all of the newlines
{} # Pop a newline because the interpreter prints a newline :(


# pb - 17 bytes

^w[B!0]{>}<vb[32]


Goes to the last character of the input and puts a space on the canvas cell representing it. Because output in pb is 2D, the empty cells before it are automatically filled in with spaces when it's outputted.

# x64 ASSEMBLY (linux nasm) - 131 bytes

mov r8, [rsp+16]
mov rdi, 1
mov rdx, 1
mov rax, 1
mov rsi,n
l:syscall
inc r8
cmp byte [r8],0x00
jnz l
mov rax,60
syscall
n: db " "


build and run with:

nasm -felf64 invisible_golfed.asm
ld invisible_golfed.asm
./a.out


This will give the warning

ld: warning: cannot find entry symbol _start; defaulting to 00000000000400080


warning free version below

without warnings - 152

global _start
_start:mov r8, [rsp+16]
mov rdi, 1
mov rdx, 1
mov rax, 1
mov rsi,n
l:syscall
inc r8
cmp byte [r8],0x00
jnz l
mov rax,60
syscall
n: db " "

• When I give the program "When I give the program" on STDIN, it only prints a single space. I suggest your read the I/O defaults and revise your answer. Essentially, revise your code to take input from STDIN. – CalculatorFeline May 26 '17 at 3:15
• My bad I have it reading from the command line. I'll fix that tomorow when I get the chance. – Samuel May 26 '17 at 4:46
• Your byte-counting is not correct. With assembly language, we count th bytes of the machine code that is generated, not the characters in the instruction mnemonics. Beyond that problem, there's lots of room for optimization here. Save several bytes by changing instructions of the form MOV Rxx, x to MOV Exx, x, where x is an immediate value <= 32 bits, taking advantage of the fact that the upper 32-bits of a 64-bit register are implicitly cleared. I also don't know why you define n separately, instead of embedding it into the instruction: MOV ESI, ' '. That gets me down to 48 bytes. – Cody Gray May 26 '17 at 12:01
• You can save even more by changing all but the first instruction in the MOV reg, 1 sequence to a reg-reg move, which has a much shorter encoding: mov eax, 1+mov edx, eax+mov edi, eax. That's only 36 bytes. – Cody Gray May 26 '17 at 12:04

# C, 5733 30 bytes

-3 thanks to Tas.

f(int*a){while(*a++)puts("");}


Try it online!

' '*"$args".Length  Try it online! Python, 23 bytes print(''*len(input()))  First time • Assuming where input comes from is usually frowned upon here. You need to wrap the code in a program/method or ask the user for input. – TheLethalCoder May 26 '17 at 8:25 • @TheLethalCoder fixed! – spark May 26 '17 at 8:31 • You don't need the space between , and ' in your second version. However, that second version isn't a full program - you need a print call, and you need to fix your str.replace call (not enough arguments). – Mego May 26 '17 at 8:50 # Lua, 17 Bytes s=s:gsub("."," ") Simple regular expression substitution, replaces any character found with a space. # q/kdb+, 14 9 bytes Solution: {" "}each  Example: q){" "}each"Hello, World" " "  Explanation: Returns " " for each character of the input. Notes: I've made a shorter version (7 bytes) that does something similar: {y}'" "  ... but you have to prepend the input rather than append: q)"hello world"{y}'" " " "  # Z80Golf, 9 bytes 00000000: d5cd 0380 3001 763e 20 ....0.v>  Try it online! Disassembly:  push de ; push$0000
call $8003 ; getchar(A) jr nc, k ; jump if not EOF halt k:ld a, ' ' ; replace A with space ; memory from$000a through $7fff is$00=NOP...
; PC reaches $8000=putchar(A) and RETs to pushed address.  (If you remove the last two bytes, this is a cat program.) # dc, 12 bytes Z256r^25.5/P  Try it online! Takes input from the stack, outputs newlines to stdin. I know there's two dc answers here already, but this one uses a different approach, with math! Plus it's 6 bytes shorter, so I guess that's all right. # Explanation One of dc's three explicit printing commands is P, which takes a number and outputs it as a base 256 (technically base UCHAR_MAX+1, works on my machine) byte stream. So I need to feed it the number (where n is the length of the given string, and 10 is the codepoint of the linefeed character):  10*256^(n-1) + 10*256^(n-2) + ... + 10 = 10 * (256^(n-1) + 256^(n-2) + ... + 1) (factoring out 10) = 10 * (256^n - 1) / (256 - 1) (geometric series formula) = (256^n - 1) / 25.5 (combining constants) ~= (256^n) / 25.5 (because dc's default precision is 0)  The code is a straightforward calculation of this number, followed by P. • Argh, doesn't handle the empty string (P outputs a NUL when it pops a 0). I guess I could say it's outputting a null-terminated string...seems like a stretch though. – Sophia Lechner Jul 10 '18 at 19:43 • Also, it's only on TIO that you can tell. On my machine a NUL gets eaten silently so it works. I still feel badly about it. – Sophia Lechner Jul 10 '18 at 19:57 # Octave / Matlab, 25 23 bytes @(x)repmat(' ',size(x))  Saved 2 bytes thanks to Giuseppe Try it online! • I think the f= is unnecessary; anonymous functions / function handles are perfectly acceptable on PPCG. – Giuseppe Jul 10 '18 at 22:27 • You can also include a link to Try it online! for Octave so others can test your answer. – Giuseppe Jul 10 '18 at 22:28 # Java (JDK), 84 bytes static String m(String n){int i=0;String d="";while(i++<n.length())d+=" ";return d;}  Try it online! • Updated Sir @JoKing. – Syed Hamza Hassan Oct 22 '18 at 12:08 • This does not address my other concerns, i.e. initialising d and reusing the function. Also, wouldn't it be shorter to use an anonymous lambda? – Jo King Oct 22 '18 at 12:14 • Your suggestions are so useful, Thanks @JoKing – Syed Hamza Hassan Oct 23 '18 at 5:07 # Wren, 22 bytes Multiply the space by the length of the string. Fn.new{|a|" "*a.count}  Try it online! # Brain-Flak, 28 bytes {}{{}<>((()()()()()){})<>}<>  Try it online! {} pop one input character (because Brain-Flak always outputs a trailing newline { for each input character {} pop that character <> switch to other stack ((()()()()()){}) push 10 (newline) <> back to input stack } <> switch to other stack. This is printed implicitly when the program ends  # Keg,-lp-ir, 3 bytes ( ,  Try it online! This takes input as characters and prints a space for each character The -lp flag makes the length() function take input if the stack is empty and the -ir flag ensures that the implicit input is as characters. # 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 \ \ ## Check, 6 bytes (non-competing) ," "*o  This is non-competing as I just made Check yesterday. 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. # 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