Print invisible text

40

6

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.

Your code should not output any additional trailing newlines or spaces.

Testcases:

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

Scoring:

This is so fewest bytes wins!

Skidsdev

Posted 2017-05-25T12:50:00.213

Reputation: 9 656

1I don't get what you mean with that “0x0A”. Where should that be output? Should that be kept, so “a␠b␊c” becomes “␠␠␠␊␠”? – manatwork – 2017-05-25T12:56:14.727

1@manatwork 0x0A and 0x20 are the hexadecimal values for the Newline and Space characters respectively – Skidsdev – 2017-05-25T12:58:45.437

1“output a number of whitespace characters (0x0A and 0x20)” – Where in the output should those newline characters be? – manatwork – 2017-05-25T13:00:40.333

3These 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 – 2017-05-25T13:05:50.860

1Got it. Thanks. – manatwork – 2017-05-25T13:06:56.037

1Can we assume the input will only have printable characters? – Luis Mendo – 2017-05-25T13:30:55.200

@LuisMendo yes you can. – Skidsdev – 2017-05-25T13:51:11.660

Related – alephalpha – 2017-05-25T14:21:08.010

Can we replace existing line breaks with spaces or do we need to retain line breaks? – Thomas Ward – 2017-05-27T18:55:07.367

@ThomasWard you don't need to retain anything but the length of the input string – Skidsdev – 2017-05-28T14:33:21.463

If we print the correct number of spaces, is a trailing newline acceptable (as this is how the language outputs) – FlipTack – 2017-10-27T15:38:43.237

Answers

141

Whitespace, 311 150 77 68 65 46 41 38 bytes

-3 bytes thanks to Kevin Cruijssen
-27 bytes thanks to Ephphatha


&nbsp&nbsp
&nbsp&nbsp&nbsp	&nbsp	&nbsp
&nbsp
&nbsp&nbsp
&nbsp	
	&nbsp			
	&nbsp&nbsp
	
&nbsp&nbsp
&nbsp


Try it online!

A visible format

'\n  \n   \t \t \n \n  \n \t\n\t \t\t\t\n\t  \n\t\n  \n \n\n'

Explanation (s = space, t = tab, n = new line)

nssn     # label(NULL) - loop start
ssststsn # push 10 in the stack -> [10]
sns      # duplicate the top of the stack -> [10, 10]
sns      # duplicate the top of the stack -> [10, 10, 10]
tnts     # read a single char from input, pop the stack and store at that address -> [10, 10] [10:<char that was read>]
ttt      # pop the stack and put the value at that adress on stack -> [10,<char>] [10:<char>]
ntssn    # jump to label(0) - since label(0) is not defined, the interpreter jumps to the end of the program - if the top of the stack (char) is 0 -> [10] [10:<char>]
tnss     # pop the top of the stack and print as ascii -> [] [10:<char>]
nsnn     # go back to the label(NULL)

Rod

Posted 2017-05-25T12:50:00.213

Reputation: 17 588

26Assuming this does actually work, this definitely wins my vote for most creative answer – Skidsdev – 2017-05-25T14:25:54.550

24Wait where is the answer? Is it invisible too? – Erik the Outgolfer – 2017-05-25T14:27:01.863

16WHAT BLACK MAGIC IS THIS. Your code is not even there! -1 – Christopher – 2017-05-25T14:32:07.350

28@Christopher more like WHITEspace MAGIC – Rod – 2017-05-25T14:34:58.950

5@Rod That was just a horrible pun. – Christopher – 2017-05-25T14:51:42.767

13I knew someone would answer this question with a whitespace program – Draco18s no longer trusts SE – 2017-05-25T21:06:57.673

This should be a meta.ppcg meme. – OldBunny2800 – 2017-05-25T21:08:58.583

2You can remove the three ending newlines. – Kevin Cruijssen – 2017-05-26T07:09:15.790

@KevinCruijssen I tried without, but it was crashing :c – Rod – 2017-05-26T11:00:36.133

1

@Rod Hmmm.. Probably depends on the compiler, as it stated in the tip-answer I've linked. I have used the TIO compiler for Whitespace in the past and there I was able to remove the three trailing new-lines. Btw, why did you state it doesn't work on TIO? Your test case of 1234 does output four spaces. ;) Hmm, your code does work in TIO without the three trailing new-lines.

– Kevin Cruijssen – 2017-05-26T11:57:47.200

1@KevinCruijssen indeed, I was too focuses on the Debug tab @.@ – Rod – 2017-05-26T12:09:51.400

148 bytes edit: can't add newlines in comments apparently. This pushes the value 10 (ascii newline) to the stack, duplicates the value to use as the heap address for reading input, checks input wasn't a null byte, duplicates the 10 and outputs a newline then loops to the first duplicate command – Ephphatha – 2017-05-26T12:14:08.507

1

Turns out you can use a null label, that saves two bytes for 46 - Try it online!

– Ephphatha – 2017-05-26T12:55:47.797

@Ephphatha wow, that's awesome – Rod – 2017-05-26T13:46:49.660

4This is the first time I interact with this community, but... I absolutely had to upvote this... – frarugi87 – 2017-05-26T14:26:36.313

1

Turns out the TIO interpreter handles jumping to an undefined label as jumping to the end of the program. This lets us drop one of the define label statements and after redefining the remaining jumps/labels it ends up saving 5 bytes for a total of 41 - Try it online!

– Ephphatha – 2017-05-28T13:36:18.360

1

There's actually no need to preseed the stack outside the loop. if we move the push after the label, we can just copy it as many times as needed for a full loop which removes one of the duplicates. 38 bytes

– Ephphatha – 2017-05-30T22:55:42.963

60

Japt, 1 byte

ç

Try it online!

Tom

Posted 2017-05-25T12:50:00.213

Reputation: 3 078

22Does japt seriously have a builtin for this? Damn... – Skidsdev – 2017-05-25T13:06:28.577

23@Mayube well it has a builtin to replace all characters in a string with another, and the default replacement is a space ;) – Tom – 2017-05-25T13:12:09.350

4

Very nice! For those running the program, you can add the -Q flag into the input to put quotes around the output. TIO

– Oliver – 2017-05-25T13:57:21.033

38

Haskell, 7 bytes

(>>" ")

Try it online! Usage: (>>" ") "Hello, world!".

Given two lists (and strings are lists of characters in Haskell) the >> operator will repeat the second list as many times as the first list has elements. Setting " " as second argument means we concatenate as many spaces as the input string is long.


Alternative (same byte count):

(' '<$)

Try it online! Usage: (' '<$) "Hello, world!".

Given some value and a list, the <$ operator replaces each value in the list with the given value. Thus 5 <$ "abc" results in [5,5,5], and ' ' <$ "abc" in " ".

The function can equivalently be written as (<$)' ', in case you want to find some more marine creatures in my code.

Laikoni

Posted 2017-05-25T12:50:00.213

Reputation: 23 676

18Its like an adorable little finless fish – Taylor Scott – 2017-05-25T13:27:31.690

21

brainfuck, 18 bytes

++++++++++>,[<.>,]

Try it online!

Prints one newline for each byte of input. Printing spaces instead would add 4 bytes.

Nitrodon

Posted 2017-05-25T12:50:00.213

Reputation: 9 181

4

For posterity: Mika Lammi posted a clever 16-byte answer that got buried. ,[>++++++++++.,]

– Lynn – 2018-06-23T14:03:17.540

18

Python, 19 bytes

lambda s:' '*len(s)

Gábor Fekete

Posted 2017-05-25T12:50:00.213

Reputation: 2 809

17

Retina, 3 4 bytes

S\`.

Old version, doesn't work because Retina prints a trailing line feed.

.
 

(The second line contains a space).

TheLethalCoder

Posted 2017-05-25T12:50:00.213

Reputation: 6 930

2

The retina TIO is quite easy to use. Here is your answer

– Digital Trauma – 2017-05-25T17:44:52.047

2Unfortunately, Retina prints a trailing linefeed by default. You'll need to prepend \\`` to avoid that. Then it's shorter to useS\`.` though, which replaces each character with a linefeed (because it splits the input around each character). – Martin Ender – 2017-06-07T09:54:13.517

@MartinEnder Ahhh wasn't sure if that was a Retina or TIO thing. Thanks for the help on saving a byte there though! – TheLethalCoder – 2017-06-07T09:57:24.047

14

sed, 7 bytes

s/./ /g

Try it online!

Riley

Posted 2017-05-25T12:50:00.213

Reputation: 11 345

13

Brainfuck, 16 bytes

Prints newlines.

,[>++++++++++.,]

Mika Lammi

Posted 2017-05-25T12:50:00.213

Reputation: 1 151

12

C#, 28 24 bytes

s=>"".PadLeft(s.Length);

Old version using the string constructor for 28 bytes:

s=>new string(' ',s.Length);

TheLethalCoder

Posted 2017-05-25T12:50:00.213

Reputation: 6 930

3Wanted to do exactly the same – LiefdeWen – 2017-05-25T12:59:31.053

1@StefanDelport Gotta be quick with C# when I'm around :) There's Linq approaches to do the same but they're all a LOT longer... – TheLethalCoder – 2017-05-25T13:00:49.467

9

Retina, 5 bytes

\`.
¶

Try it online! Changes everything into newlines. The \` suppresses the extra newline Retina would normally output.

Neil

Posted 2017-05-25T12:50:00.213

Reputation: 95 035

9

Mathematica, 21 bytes

StringReplace[_->" "]

alephalpha

Posted 2017-05-25T12:50:00.213

Reputation: 23 988

1If charlist input was allowed, this could be #/._->" "&. Sadly, the input is a string and Characters[] makes it one byte longer than your solution :( – CalculatorFeline – 2017-05-26T03:03:52.320

1Doesn't this need a # and a & in it? E.g. StringReplace[#,_->" "]& – Ian Miller – 2017-05-26T03:58:53.610

3

@IanMiller Not in Mathematica 10.4 or 11. http://reference.wolfram.com/language/ref/StringReplace.html

– alephalpha – 2017-05-26T04:37:58.603

2Ah ok. I only have 10.3. Maybe time to upgrade... – Ian Miller – 2017-05-26T04:38:41.063

8

JavaScript ES6, 22 bytes

a=>a.replace(/./g," ")

f=a=>a.replace(/./g," ");

var test = f("Hello, World!");
console.log(test, test.length);

Tom

Posted 2017-05-25T12:50:00.213

Reputation: 3 078

3Huh, I thought "oh darn, it'd have to be s=>s.replace(/[^]/g," "), a byte longer than the other solution". It didn't occur to me that newlines are allowed in the output :P – ETHproductions – 2017-05-25T15:05:20.143

8

C, 31 bytes

f(char*c){puts(""),*c++&&f(c);}

sigvaldm

Posted 2017-05-25T12:50:00.213

Reputation: 341

1

How does this differ from your other C answer? Clearly this one is shorter, but should you have simply edited the other one? Should it just be one answer with two solutions?

– Tas – 2017-05-26T01:09:23.257

4@Tas First of all, I guess in some sense I feel this is not as good as the other one eventhough it's shorter, because it doesn't actually compile as-is. It's just a function so you need to write some main routine around it. However, it is shorter and others seems to post just functions. Clearly it's two very different solutions. One is not the refinement of the other, so to me it makes sense that it should be two different answers. However, I'm new to this community. Is the consensus that one user only posts one answer? If so I will do that next time. – sigvaldm – 2017-05-26T08:24:41.737

Should the comma really be a comma and not a semicolon? – Oskar Skog – 2017-05-27T11:12:55.513

1@OskarSkog well, in this case it doesn't matter that much because there is no lhs – cat – 2017-05-28T11:23:57.427

1@OskarSkog Yes, it should be a comma. As @cat says, it doesn't really matter in this case but I chose comma for variation :) The comma operator evaluates two expressions (e.g. i++, j++ in a for loop) and returns the rightmost one. An important detail is that the recursion has to stop somehow. && doesn't evaluate it's rhs if it's lhs is false. *c++ evaluates false when it points to the null-termination of the string. – sigvaldm – 2017-05-29T18:55:35.173

7

05AB1E, 3 bytes

vð?

Try it online!

v   # For each character...
 ð? #    Output a space without a newline

Other 3 byte solutions (Thanks Magic Octopus Urn and Kevin Cruijssen for most of these)

v¶? # For each character print a newline (without adding a newline)
võ, # For each character print the empty string with a newline
gð× # Get the length, concatenate that many copies of space
g¶× # Get the length, concatenate that many copies of newline
Sð: # Split, push a space, replace each char in input with a space
ðs∍ # Push ' ', swap, make the string of spaces as long as the input was
võJ # For each char, push a space and ''.join(stack)
v¶J # For each char, push a newline and ''.join(stack)
€ðJ # For each char, push a space. Then ''.join(stack)
ۦJ # For each char, push a newline. Then ''.join(stack)

Riley

Posted 2017-05-25T12:50:00.213

Reputation: 11 345

1Other solution: gð×, the rest I came up with were above 3 like: õ‚.B¤ – Magic Octopus Urn – 2017-05-25T17:16:38.640

2Another fun one: Sð: – Magic Octopus Urn – 2017-10-26T14:29:52.173

1More fun: ðs∍ – Magic Octopus Urn – 2018-10-22T16:33:06.123

Some more alternative 3-byters: võJ/v¶J; €ðJ/€¶J. And since a sequence of characters as I/O is allowed by default when strings I/O is asked, some 2-byte versions are possible: €ð/€¶/εð/ε¶ and ð:/¶:. Although since this is a pretty old challenge and all other answers use actual strings, I could understand if you kept it as string I/O.

– Kevin Cruijssen – 2019-11-15T13:33:32.413

7

Excel VBA, 17 15 Bytes

Anonymous VBE immediate window funtion that takes input from cell [A1] and outputs spaces of length of the input to the VBE immediate window

?Spc([Len(A1)])

Taylor Scott

Posted 2017-05-25T12:50:00.213

Reputation: 6 709

7

PHP, 28 Bytes

for(;a&$argn[$i++];)echo" ";

Try it online!

PHP, 29 Bytes

<?=str_pad('',strlen($argn));

Try it online!

Jörg Hülsermann

Posted 2017-05-25T12:50:00.213

Reputation: 13 026

6

Octave, 14 bytes

@(a)["" 0*a+32]

alephalpha

Posted 2017-05-25T12:50:00.213

Reputation: 23 988

6

CJam, 4 bytes

q,S*

Try it online!

Explanation

q     e# Read input
 ,    e# Length
  S*  e# Repeat space that many times

Business Cat

Posted 2017-05-25T12:50:00.213

Reputation: 8 927

6

C, 45 bytes

Using main. Compile with gcc, ignore warnings.

main(c,v)char**v;{while(*(v[1]++))puts("");}

Usage:

$./a.out "Hello, World!"

sigvaldm

Posted 2017-05-25T12:50:00.213

Reputation: 341

1Any reason why you can't put char**v in main(c,v)? – CalculatorFeline – 2017-05-26T03:07:15.760

@CalculatorFeline At least GCC 6.3.1 compiling simply with gcc main.c doesn't seem to allow mixing ANSI function definition with K&R function definition, so main(c,char**v) won't compile. I either have to do main(int c,char**v) or main(c,v)char**v; of which the latter is 3 bytes shorter. You wouldn't by chance know any flag or something which allows mixing these styles? – sigvaldm – 2017-05-26T08:12:59.877

3No, you can't mix 'em. There's no flag that allows that. K&R style is long obsolete, used only for code golfing and obfuscation purposes. – Cody Gray – 2017-05-26T11:50:28.263

And I'm guessing removing char**v entirely doesn't compile either. – CalculatorFeline – 2017-05-26T20:39:54.657

@CalculatorFeline If you omit char** entirely the compiler will interpret it as int. If I'm not mistaken you get an error trying to dereference an int and even if you didn't the program wouldn't do what you expected it to do since an int consumes several chars and therefore you never get a NULL value. – sigvaldm – 2017-05-29T19:04:37.700

I think you could just do main(char**v){...}, if I'm not mistaken – Conor O'Brien – 2017-05-30T21:22:30.440

How would you be able to do that, @conor? The first parameter to main is an int. Your declaration is missing the first parameter! – Cody Gray – 2017-05-31T06:25:20.407

@CodyGray my mistake. I thought I remembered reading that using only argv as a parameter was valid somewhere – Conor O'Brien – 2017-05-31T11:40:56.047

5

JavaScript (ES6), 23 bytes

s=>" ".repeat(s.length)

Justin Mariner

Posted 2017-05-25T12:50:00.213

Reputation: 4 746

5

Python 2, 25 bytes

exec'print;'*len(input())

-2 bytes thanks to Loovjo
-2 bytes in the invalid code thanks to totallyhuman :p
-3 bytes

HyperNeutrino

Posted 2017-05-25T12:50:00.213

Reputation: 26 575

1You can remove the parens after exec since it's a keyword in Python 2 – Loovjo – 2017-05-25T13:36:06.440

1@Loovjo Oh right, Python 2. Thanks! – HyperNeutrino – 2017-05-25T13:47:13.140

I know this is old and stuff but exec'print;'*len(input()) works. – totallyhuman – 2017-07-20T14:28:51.480

1@totallyhuman oh true, thanks :P – HyperNeutrino – 2017-07-20T15:15:54.780

Oh, my bad, didn't think of that. – totallyhuman – 2017-07-20T15:16:40.547

Actually, it doesn't work. input() in python2 evaluates the contents. So this errors with SyntaxError: unexpected EOF while parsing for Hello, World!. You need to use raw_input(). – The Matt – 2018-07-08T19:30:39.107

@TheMatt Actually, thanks for pointing that out; thanks to current policies, that actually does work (and allows newlines) because you can request for input to be enclosed in quotes or whatever is required for the language specs in that respect – HyperNeutrino – 2018-07-09T21:28:16.027

Ah ok, can you please point out where it says enclosed in quotes is valid. I am just not seeing it. Also, for what it is worth, print' '*(len(input())-1) is also 25 bytes. – The Matt – 2018-07-09T22:08:19.513

1@TheMatt it's probably not in the problem specs but it's one of the default acceptable input methods. Try looking on meta, I don't want to go looking for it right now – HyperNeutrino – 2018-07-13T16:23:15.777

5

Perl 5, 7 bytes

-1 byte thanks to @Xcali

6 bytes of code + -p flag.

y// /c

Try it online!

Quite straight forward : replaces every character with a space.

Dada

Posted 2017-05-25T12:50:00.213

Reputation: 8 279

1y// /c is one byte shorter. – Xcali – 2017-10-26T18:49:57.617

5

Excel, 18 bytes

=REPT(" ",LEN(A1))

Pretty boring and one byte longer than the VBA answer.

Engineer Toast

Posted 2017-05-25T12:50:00.213

Reputation: 5 769

5

><>, 7 bytes

i0(?;ao

The program is a loop

i         //Push a character from the input onto the stack
 0        //Add a 0 to the stack
  (       //Pop the top two values of the stack, and push a 1 if the second is less than the first (In this case, the input has all been read), else push a 0
   ?      //Pop the top of the stack. If the value is a 0, skip the next instruction
    ;     // Terminate the program
     a    // Add a newline to the stack
      o   // Pop the top character of the stack and print it

AGourd

Posted 2017-05-25T12:50:00.213

Reputation: 271

5

V, 2 bytes

Ò 

Try it online!

Note the trailing space!

James

Posted 2017-05-25T12:50:00.213

Reputation: 54 537

5

Hexagony, 12 11 bytes

-1 byte thanks to Martin Ender

,<.;.M@.>~8

Try it online!

Here is the expanded hex:

  , < . 
 ; . M @
. > ~ 8 .
 . . . .
  . . .

While there is input, this code runs:

,        # Get input
 <       # Turn right (SE) if we didn't get EOF
  M8     # Set the memory edge to 778 which is 10 (mod 256)
    ;    # Print as a character (newline)
     >   # Redirect East
      ~  # Multiply by -1. This makes the pointer go to the top when it runs off the edge
       8 # Effectively a no-op.

When EOF is reached:

,    # Get input
 <   # Turn left (NE)
  8  # Effectively a no-op
   @ # End program

Riley

Posted 2017-05-25T12:50:00.213

Reputation: 11 345

You can print a linefeed in three bytes with M8; (which gives 778 = 10 (mod 256)). That should allow you to move the ~ where the ; is right now, saving a byte. – Martin Ender – 2017-06-07T09:52:28.877

4

PHP, 36 bytes

<?=str_repeat('
',strlen($argv[1]));

Try it online!

Outputs newlines because spaces are too mainstream

Skidsdev

Posted 2017-05-25T12:50:00.213

Reputation: 9 656

$argn instead of $argv[1] save 4 bytes. Run with the -F option – Jörg Hülsermann – 2017-06-15T16:23:26.730

4

Pyth, 3 bytes

*dl

Try it!

Python equivalent: len(input())*" "

jmk

Try this!

Python equivalent: "\n".join(map("", input()))

smb

Try that!

Python equivalent: "".join(map("\n",input())

VQk

Try!

Python equivalent: For N in input():print("")

KarlKastor

Posted 2017-05-25T12:50:00.213

Reputation: 2 352

@StanStrum: It outputs newlines. Newlines are also allowed per the challenge description above. You can see this better from this example input

– KarlKastor – 2017-09-18T19:41:38.933

4

Cubix, 6 bytes

Wahoo a 6 byter!

wi?@oS

Cubified

  w
i ? @ o
  S
  • i gets input
  • ? test top of stack
    • if negative (EOI) redirect onto w lane change which umps to the @ halt
    • if 0 (null) halt this shouldn't be hit
    • if positive Sow push space to the stack, output and change lane onto i

Try it online!

MickyT

Posted 2017-05-25T12:50:00.213

Reputation: 11 735

1Sweet, it's not too often a Cubix program is this short :-) – ETHproductions – 2017-05-27T15:40:27.717

4

C, 32 bytes

Try Online modifying characters into spaces

f(char*t){(*t=*t?32:0)&&f(t+1);}

C, 37 bytes

Try Online Left-padding the end-of-string with its length

f(char*t){printf("%*c",strlen(t),0);}

Khaled.K

Posted 2017-05-25T12:50:00.213

Reputation: 1 435

4

APL (Dyalog) 13.2, 1 byte

Prints only spaces.

 prototype (numbers become zeros, characters become spaces)

Try it online!

Adám

Posted 2017-05-25T12:50:00.213

Reputation: 37 779

4

Pepe, 46 37 bytes

REEeRREeeeREEEEErEeeEeeeeerEEeeeEreee

Try it online!

Explanation:

REEe       # Input (string) in R
RREeee     # Push reverse pointer position, or length of input - 1
           # R flag: push in beginning
REEEEE     # ...add 1
rEeeEeeeee # Push space in r
rEEeeeE    # ...R times
reee       # Output whole stack

u_ndefined

Posted 2017-05-25T12:50:00.213

Reputation: 1 253

4

Poetic, 81 bytes

the berenstein bears
i remember a series i spelled wrong
o m gee,i do remember it

Try it online!

The misspelling is intentional. (...or is it?)

JosiahRyanW

Posted 2017-05-25T12:50:00.213

Reputation: 2 600

3

Gema, 4 characters

?=\ 

(There is a space at the end of code.)

Sample run:

bash-4.4$ echo -n 'Hello, World!' | gema '?=\ '
             bash-4.4$ echo -n 'Hello, World!' | gema '?=\ ' | wc
      0       0      13

manatwork

Posted 2017-05-25T12:50:00.213

Reputation: 17 865

3

Jelly, 2 bytes

⁶ṁ

Try it online!

Erik the Outgolfer

Posted 2017-05-25T12:50:00.213

Reputation: 38 134

3

APL (Dyalog), 3 bytes

Prints only newlines.

0/⍪

Try it online!

 table (makes string into column matrix)

0/ replicate each column zero times

Adám

Posted 2017-05-25T12:50:00.213

Reputation: 37 779

3

Scala, 15 bytes

s=>" "*s.length

jaxad0127

Posted 2017-05-25T12:50:00.213

Reputation: 281

I created a Try it online for your program.

– jrook – 2018-10-22T05:40:55.477

3

dc, 25 18 bytes

-1 byte thanks to brhfl

Z[1-d0<L32P]sLd0<L

Try it online!

Explanation:

Z[1-d0<L32P]sLd0<L
                    Implicit input
Z                   Get length
 [         ]sL      Create a funcion and saves in L
              d0<L  If length > 0, call L
  1-                Subtract 1 from the length
    d0<L            If length > 0, call L
        32P         Print space

Felipe Nardi Batista

Posted 2017-05-25T12:50:00.213

Reputation: 2 345

Woah! It's worse than German. It would be neat if you explained how it works ;) – NieDzejkob – 2017-05-29T17:01:47.880

@NieDzejkob there :D – Felipe Nardi Batista – 2017-05-29T17:57:48.430

@Felipe You can shave off one byte by using the ASCII code point for a space instead of a string containing a space: 32P instead of [ ]P. I doubt it can be golfed down much further... – brhfl – 2017-10-26T17:14:47.407

@brhfl didn't know i could do that, thanks – Felipe Nardi Batista – 2017-10-26T18:43:11.013

3

C (tcc), 31 bytes

I opted to output newlines since it's shorter...

f(char*s){for(;*s++;puts(""));}

Try it online!

cleblanc

Posted 2017-05-25T12:50:00.213

Reputation: 3 360

3

shortC, 16 bytes

f(C*a){W*a++)P' 

Note the trailing space at end of code.

Conversions in this program:

  • C -> char
  • W -> while(
  • P -> putchar(

The resulting program looks like this:

f(char *a){while(*a++)putchar(' ');}

How that works:

  • while(*a++) loops until it reaches the last index of the string a.
  • putchar(' '); prints a space for each index of a.

Try it online!

MD XF

Posted 2017-05-25T12:50:00.213

Reputation: 11 605

3

Java 8, 24 bytes

s->s.replaceAll("."," ")

Try it here.

Java 7, 49 bytes

String c(String s){return s.replaceAll("."," ");}

Try it here.

Kevin Cruijssen

Posted 2017-05-25T12:50:00.213

Reputation: 67 575

3

Chip, 2 bytes

*f

Try it online!

Chip reads in a byte, does whatever calculations are in the code, and writes a byte. So, for each byte of input, we ignore the input and write 0x20 instead. The empty Chip program would replace each byte of input with a null byte of output.

*    Source element, activates any neighbor elements
 f   Output element for the bit 0x20, when active this bit is set in the output

Transposing the two characters would result in the same thing. I opted to use spaces, since 0x20 requires only one bit to be set. 0x0a requires setting two bits. Code for that could be:

b*d

Phlarx

Posted 2017-05-25T12:50:00.213

Reputation: 1 366

3

Shell utils, 14 12 bytes

tr ' -~' ' '

tr translates characters in the first parameter, into the corresponding one in the second parameter. (space)-~ is a range for space (32) to tilda (126), the first and last printable ASCII characters. They are mapped into a space; tr duplicates the last character in the output list if it is shorter than the input list.

CSM

Posted 2017-05-25T12:50:00.213

Reputation: 219

3You could shave off a couple of bytes with different quoting styles (\ -~ instead of ' -~') and you could even get away without quoting the first parameter at all if you use a control-character byte. – RJHunter – 2017-05-29T03:53:39.990

1That brings it down to 9 bytes: tr ␁-~ \ (␁=^A) – L3viathan – 2017-11-24T08:11:42.833

2

APL, 11 6 bytes

5 bytes saved thanks to @Adám

' '⍴⍨≢

Uses the Dyalog Classical character set.

Uriel

Posted 2017-05-25T12:50:00.213

Reputation: 11 708

You can golf this significantly. First, swap the arguments of rho to remove the parentheses: {' '⍴⍨⍴,⍵}, then use tally rather than rho to remove the comma: {' '⍴⍨≢⍵}, and finally, make it into a train to remove the braces and omega: ' '⍴⍨≢.

– Adám – 2017-05-25T14:13:12.953

@Adám thanks! never seen the tally before – Uriel – 2017-05-25T14:32:38.477

No problem. I'll be happy to teach you more over in the APL chat room.

– Adám – 2017-05-25T14:33:40.293

How is this 5 bytes? – Erik the Outgolfer – 2017-05-26T13:52:44.187

@EriktheOutgolfer fixed, thanks. it counts 6 with the Dyalog char set – Uriel – 2017-05-26T14:11:51.820

2

PowerShell, 21 bytes

[char[]]"$args"|%{""}

Try it online!

prints newlines.

colsw

Posted 2017-05-25T12:50:00.213

Reputation: 3 195

.....I like it! – briantist – 2017-05-26T04:08:44.250

@briantist thanks for the TIO link, need to get into the habit of doing them myself. – colsw – 2017-05-26T08:29:45.123

can't go wrong, it creates the whole post for you. That's why I use it even when the code itself can't run in TIO

– briantist – 2017-05-26T11:56:29.990

2

Perl 6, 10 bytes

{S:g/./ /}

Basic string substitution.

Sean

Posted 2017-05-25T12:50:00.213

Reputation: 4 136

2

JavaScript (ES8), 22 bytes

s=>"".padEnd(s.length)

Shaggy

Posted 2017-05-25T12:50:00.213

Reputation: 24 623

2

Convex, 2 bytes

,*

Try it online!

Simply takes the length of the input and multiplies by newlines (which are at the bottom of the stack)

GamrCorps

Posted 2017-05-25T12:50:00.213

Reputation: 7 058

2

Bash, 16 bytes

printf %*s ${#1}

Try it online!

Uses parameter expansion count the length of the argument ${#1}, and then printf to output an empty string space-padded to that same length.

RJHunter

Posted 2017-05-25T12:50:00.213

Reputation: 141

2

Perl 5, 6 + 1 = 7 bytes

Uses the -p flag.

y// /c

y/// is the transliteration operator: the first list is translated to the corresponding character in the second list. Without the c, this does nothing, but the c complements the first list, so all characters are transliterated to a space.

Chris

Posted 2017-05-25T12:50:00.213

Reputation: 1 313

2

Aceto, 5 bytes

Trivial in Aceto:

p
,'O

Reads a character, pushes a space, prints it, and goes back to the start.

L3viathan

Posted 2017-05-25T12:50:00.213

Reputation: 3 151

2

T-SQL, 32 bytes

SELECT SPACE(LEN(a+'x')-1)FROM t

Microsoft SQL's LEN function ignores trailing spaces, so this hacky workaround is required.

Input is stored in varchar column a in pre-existing table t, per our input rules.

BradC

Posted 2017-05-25T12:50:00.213

Reputation: 6 099

2

TI-Basic, 13 bytes

For(I,2,length(Ans
Disp "
End

Loop starts at 2 because an additional newline is printed before Done at the end of the program.

Timtech

Posted 2017-05-25T12:50:00.213

Reputation: 12 038

2

MATL, 3 4 bytes

nqZ"

Try it online!

Today I learnt that MATLAB has a function for creating a string of spaces!

n - count the number of bytes in input string
q - decrement by 1, because the implicit disp at the end adds a newline (so the number of spaces required is string length - 1)
Z" - blanks command: create a string with the specified number of spaces in it
(Implicit output at end, with trailing newline.)

sundar - Reinstate Monica

Posted 2017-05-25T12:50:00.213

Reputation: 5 296

2

R, 37 23 bytes

gsub("."," ",scan(,""))

Try it online!

14 bytes saved by ngm.

JayCe

Posted 2017-05-25T12:50:00.213

Reputation: 2 655

apart from using gsub, strrep exists as well, so strrep(" ",nchar(scan,""))) would work (even though it's longer than @ngm 's suggestion) – Giuseppe – 2018-07-10T20:27:17.603

@Giuseppe Is this a recent function? I can't believe I'm hearing about it for the first time. – JayCe – 2018-07-10T20:37:07.473

It appears to have been added in 3.3.0. I haven't really found a great use for it; usually the first thing I do when I see a string is to utf8ToInt it and then I can just use rep for mostly the same purpose, and rep has finer control beyond just times, with each, length.out – Giuseppe – 2018-07-10T21:01:08.433

2

Powershell, 18 bytes

$args|% t*y|%{' '}

The expression % t*y splits input strings into chars. This solution has same length as solution in the Matt's comment: " "*"$args".length.

Testscript (use LF only mode in your editor):

$f = {
$args|% t*y|%{' '}
}

@(
,(13, "Hello, World!")
,(2, "Hi")
,(45, "   Don't
Forget about
Existing
Whitespace!   ")
,(0, "")
,(13, "             ")
,(1,"
")
) | % {
    $len,$source=$_
    $r = &$f $source
    $l=$r.length
    "$($l-eq$len): $l"
}

Output:

True: 13
True: 2
True: 45
True: 0
True: 13
True: 1

Powershell + Regex, 20 bytes

$args-replace'.',' '

mazzy

Posted 2017-05-25T12:50:00.213

Reputation: 4 832

2

J, 4 bytes

LF"0

Try it online!

Converts each cell (each character in this case) to the linefeed character. LF is a built-in noun for '\n'. "0 attached to a noun converts it to a verb with the given rank.

Bubbler

Posted 2017-05-25T12:50:00.213

Reputation: 16 616

2

Ruby -p, 10 bytes

$_=$/*~/$/

Try it online!

Explanation:

$_=          Output equals
   $/        the output separator (defaults to newline)
     *       repeated a number of times equal to
      ~      the index in the input of the first match of
        /$/  the regular expression for "end of line"

histocrat

Posted 2017-05-25T12:50:00.213

Reputation: 20 600

2

Runic Enchantments, 9 bytes

" "il͍*@

Try it online!

Note that spaces and newlines need to be escaped in the input, as input is automatically split otherwise.

Draco18s no longer trusts SE

Posted 2017-05-25T12:50:00.213

Reputation: 3 053

2

Cascade, 14 11 9 8 bytes

? .'
,^\

Try it online!

-1 byte thanks to Jo King realizing it's shorter to just turn into two lines

Since the program never uses the return values of anything other than , and ', and the order spaces are printed in doesn't matter (since they're indistinguishable), ^ can be used backwards: instead of printing a space then recurring, this recurs then prints a space.

Ungolfed, this looks something like:

 @
 ?
 |\
 , \
    ^
   / \
  /   .
 |    \
 |     '
 |

If tabs are legal whitespace alongside spaces and newlines:

Cascade, 7 bytes

? .
,^9

Try it online!

thanks to Jo King.

Unrelated String

Posted 2017-05-25T12:50:00.213

Reputation: 5 300

Note that this uses ? over _ because end of input returns -1, and ? tests for a positive center, but _ only tests for a left not equal to 0. – Unrelated String – 2019-11-16T22:26:46.003

The challenge spec seems to indicate that the only acceptable whitespace characters are space and newline, but that's still a great idea. – Unrelated String – 2019-11-17T11:16:44.423

1

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$);

snail_

Posted 2017-05-25T12:50:00.213

Reputation: 1 982

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 – 2018-03-03T16:18:44.760

1

Mathematica, 30 bytes

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

J42161217

Posted 2017-05-25T12:50:00.213

Reputation: 15 931

1

Lua, 25 bytes

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

Same length as:

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

Try it online!

Felipe Nardi Batista

Posted 2017-05-25T12:50:00.213

Reputation: 2 345

Test output length here

– Felipe Nardi Batista – 2017-05-25T14:19:19.037

1

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.

sergiol

Posted 2017-05-25T12:50:00.213

Reputation: 3 055

1

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!

TheLethalCoder

Posted 2017-05-25T12:50:00.213

Reputation: 6 930

1

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 – 2017-05-26T03:48:57.850

1

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 :(

Riley

Posted 2017-05-25T12:50:00.213

Reputation: 11 345

1

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.

undergroundmonorail

Posted 2017-05-25T12:50:00.213

Reputation: 5 897

1

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 " "

Samuel

Posted 2017-05-25T12:50:00.213

Reputation: 191

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 – 2017-05-26T03:15:17.723

My bad I have it reading from the command line. I'll fix that tomorow when I get the chance. – Samuel – 2017-05-26T04:46:42.747

1Your 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 – 2017-05-26T12:01:37.923

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 – 2017-05-26T12:04:20.630

1

C, 57 33 30 bytes

-3 thanks to Tas.

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

Try it online!

MD XF

Posted 2017-05-25T12:50:00.213

Reputation: 11 605

1

PowerShell, 18 bytes

' '*"$args".Length

Try it online!

briantist

Posted 2017-05-25T12:50:00.213

Reputation: 3 110

1

Python, 23 bytes

print(''*len(input()))

First time

spark

Posted 2017-05-25T12:50:00.213

Reputation: 111

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 – 2017-05-26T08:25:54.247

@TheLethalCoder fixed! – spark – 2017-05-26T08:31:35.970

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 – 2017-05-26T08:50:31.143

1

Lua, 17 Bytes

s=s:gsub("."," ")

Simple regular expression substitution, replaces any character found with a space.

Delya Erricson

Posted 2017-05-25T12:50:00.213

Reputation: 81

1

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}'" "
"           "

streetster

Posted 2017-05-25T12:50:00.213

Reputation: 3 635

1

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.)

Lynn

Posted 2017-05-25T12:50:00.213

Reputation: 55 648

1

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.

Sophia Lechner

Posted 2017-05-25T12:50:00.213

Reputation: 1 200

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 – 2018-07-10T19:43:18.713

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 – 2018-07-10T19:57:21.100

1

Octave / Matlab, 25 23 bytes

@(x)repmat(' ',size(x))

Saved 2 bytes thanks to Giuseppe

Try it online!

PieCot

Posted 2017-05-25T12:50:00.213

Reputation: 1 039

I think the f= is unnecessary; anonymous functions / function handles are perfectly acceptable on PPCG. – Giuseppe – 2018-07-10T22:27:04.967

You can also include a link to Try it online! for Octave so others can test your answer.

– Giuseppe – 2018-07-10T22:28:25.453

1

Java (JDK), 84 bytes

static String m(String n){int i=0;String d="";while(i++<n.length())d+=" ";return d;}

Try it online!

Syed Hamza Hassan

Posted 2017-05-25T12:50:00.213

Reputation: 129

Updated Sir @JoKing. – Syed Hamza Hassan – 2018-10-22T12:08:03.540

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 – 2018-10-22T12:14:32.707

Your suggestions are so useful, Thanks @JoKing – Syed Hamza Hassan – 2018-10-23T05:07:52.597

1

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.

Lyxal

Posted 2017-05-25T12:50:00.213

Reputation: 5 253

1

Wren, 22 bytes

Multiply the space by the length of the string.

Fn.new{|a|" "*a.count}

Try it online!

user85052

Posted 2017-05-25T12:50:00.213

Reputation:

1

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

Dorian

Posted 2017-05-25T12:50:00.213

Reputation: 1 521

1

x86-16 ASM, IBM PC DOS, 11 bytes

Binary:

00000000: 8a0e 8000 49b8 200a cd10 c3              ....I. ....

Unassembled:

D1 EE       SHR  SI, 1          ; SI to 80H (SI intialized at 100H) 
AC          LODSB               ; load string length into AL
91          XCHG AX, CX         ; put input string length into CX
49          DEC  CX             ; remove leading whitespace from length
AC          LODSB               ; load whitespace delimiter into AL
B4 0A       MOV  AH, 0AH        ; BIOS "write character CX number of times" function
CD 10       INT  10H            ; call BIOS, display to console
C3          RET                 ; return to DOS

Explanation:

Input is via command line, though all that's important is the length. Command line input length is always stored at memory address DS:0080H in DOS, so put that into CX. DOS includes the space between the executable name and the command line args string in this number.

For example: in FOO.COM Hello, length is 6 and command line string is " Hello", or calling as FOO.COM/Hello, command line string is "/Hello" (Note: those are the the only valid characters for the character immediately after the executable name). This first character (will be a space when called normally) is what is displayed as the "invisible text" for output. This builds in a handy little "debug mode" where you can use a slash instead of a space to actually be able to test your output is the right length.

Then, use the IBM PC BIOS's INT 10H "Write character only at cursor position" (0AH) function that writes the same character CX number of times.

Example Output:

Admittedly, displaying 13 chars of whitespace is not very interesting in a screenshot. However, by using a slash instead of a space ("debug mode") you can actually see that you are displaying the right number of chars.

enter image description here

640KB

Posted 2017-05-25T12:50:00.213

Reputation: 7 149

1

naz, 40 bytes

2a2x1v1x1f1r3x1v2e0m4a8m1o1f0x1x2f0a0x1f

Works for any input string terminated with the control character STX (U+0002).

Explanation (with 0x commands removed)

2a2x1v                 # Set variable 1 equal to 2
1x1f1r3x1v2e           # Function 1
                       # Read a byte of input
                       # Jump to function 2 if it equals variable 1
            0m4a8m1o1f # Otherwise, output a space and jump back to the start of function 1
1x2f0a                 # Function 2
                       # Add 0 to the register
1f                     # Call function 1

sporeball

Posted 2017-05-25T12:50:00.213

Reputation: 461

1

GolfScript, 5 bytes

Port of CJam answer.

," "*

Try it online!

user85052

Posted 2017-05-25T12:50:00.213

Reputation:

0

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.

Shaun Bebbers

Posted 2017-05-25T12:50:00.213

Reputation: 1 814

It is now later. – CalculatorFeline – 2017-05-26T03:08:22.760

0

REXX 27 Bytes

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

theblitz

Posted 2017-05-25T12:50:00.213

Reputation: 1 201

0

Powershell, 22 Bytes

' '*(Read-Host).length

Sivaprasath Vadivel

Posted 2017-05-25T12:50:00.213

Reputation: 139

1Not 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 – 2017-05-30T12:17:17.050

Length property and Len are same – Sivaprasath Vadivel – 2017-05-30T13:32:32.587

"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 – 2017-05-30T14:14:55.787

Ok...That explains it – Sivaprasath Vadivel – 2017-05-30T14:15:49.130

0

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"]
"   "

"   "

Kaz

Posted 2017-05-25T12:50:00.213

Reputation: 372

0

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.

madstap

Posted 2017-05-25T12:50:00.213

Reputation: 141

0

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?

stevefestl

Posted 2017-05-25T12:50:00.213

Reputation: 539

0

Ruby, 12 11+1 = 13 12 bytes

Uses the -p flag. -1 byte from Martin Ender.

gsub /./,$/

Try it online!

Value Ink

Posted 2017-05-25T12:50:00.213

Reputation: 10 608

0

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.

Esolanging Fruit

Posted 2017-05-25T12:50:00.213

Reputation: 13 542

0

Bash + Coreutils, 11 Bytes

tr -c \ \

markasoftware

Posted 2017-05-25T12:50:00.213

Reputation: 346

0

J, 6 bytes

' '#~#

Try it online!

Explanation

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

Conor O'Brien

Posted 2017-05-25T12:50:00.213

Reputation: 36 228

4 bytes ''"0 outputs n newlines. – FrownyFrog – 2017-10-28T01:07:05.253

@FrownyFrog You should make your own answer, it's quite different from mine – Conor O'Brien – 2017-10-28T03:51:02.643

0

Common Lisp, 32 bytes

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

Try it online!

Renzo

Posted 2017-05-25T12:50:00.213

Reputation: 2 260

0

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.

user41805

Posted 2017-05-25T12:50:00.213

Reputation: 16 320

0

Befunge-98 (PyFunge), 5 bytes

#@~a,

Try it online!

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

MildlyMilquetoast

Posted 2017-05-25T12:50:00.213

Reputation: 2 907

0

dc, 18 bytes

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

Try it online!

cab404

Posted 2017-05-25T12:50:00.213

Reputation: 141

0

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)

LyricLy

Posted 2017-05-25T12:50:00.213

Reputation: 3 313

0

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!

ATaco

Posted 2017-05-25T12:50:00.213

Reputation: 7 898

0

Jq 1.5, 69 68 66 64 bytes

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!

jq170727

Posted 2017-05-25T12:50:00.213

Reputation: 411

1I do not know jq, but as then""else is syntactically valid, it seems like you could also omit the space in " " end. – Jonathan Frech – 2017-09-19T07:07:12.107

1As variables probably cannot begin with a digit, the spaces in <1 then and <2 then may also be superfluous. – Jonathan Frech – 2017-09-19T07:40:23.183

0

Vim, 4 bytes

VGr 

(a trailing space)

NieDzejkob

Posted 2017-05-25T12:50:00.213

Reputation: 4 630

0

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).

sundar - Reinstate Monica

Posted 2017-05-25T12:50:00.213

Reputation: 5 296

0

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!

Taylor Scott

Posted 2017-05-25T12:50:00.213

Reputation: 6 709

0

C# .NET, 84 bytes

class P{static void Main(string[]a){System.Console.Write("".PadLeft(a[0].Length));}}

Try Online

canttalkjustcode

Posted 2017-05-25T12:50:00.213

Reputation: 131