Full Width Text

44

3

Full width text is text that has a space after every character, including the last one. For instance, the first sentence of this question becomes:

F u l l   w i d t h   t e x t   i s   t e x t   t h a t   h a s   a   s p a c e   a f t e r   e v e r y   c h a r a c t e r ,   i n c l u d i n g   t h e   l a s t   o n e . 

Write a program that takes a line in text from standard input and outputs it as full-width text to standard out.

Leaderboard

var QUESTION_ID=75979,OVERRIDE_USER=52353;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

Jess Smith

Posted 2016-03-22T17:45:18.033

Reputation: 581

1So, if I understand, we can't take input as a function parameter (or output as a return value)? – Nathan Merrill – 2016-03-22T17:50:48.620

@NathanMerrill Yes, that's correct. – Jess Smith – 2016-03-22T17:51:29.860

6Usually you should allow functions too, or you exclude a lot of languages (e.g. JavaScript). – wizzwizz4 – 2016-03-22T18:00:20.207

1And the challenge would be more interesting if you had to detect whether the text was full-width and then toggle its full-width-ness, but that's just a suggestion, and there are already answers so you can't, but it's an idea for a new question... – wizzwizz4 – 2016-03-22T18:01:38.880

True. Good suggestions, thanks :) – Jess Smith – 2016-03-22T18:05:01.880

8

We have a few defaults for I/O that are based on community consensus. While you are entitled to override them, insisting on STDIN/STDOUT for I/O invalidates a bunch of answers (which assumed that the defaults apply) and make the task downright impossible in other languages (they don't have standard streams).

– Dennis – 2016-03-22T21:22:58.167

54

That is not what fullwidth text is.

– BlueRaja - Danny Pflughoeft – 2016-03-22T21:53:15.300

4

@BlueRaja-DannyPflughoeft is right. Full Width text is about underlying character encoding ( 2 bytes encoded ) required by some language ( i.e. ideograms ). In Unicode the notion of half and full size is called Unicode block

– Ludovic Frérot – 2016-03-23T09:27:15.763

I know this is a little late, but what are the rules regarding accepting stdin until someone pressed Ctrl-D to signify EOF? – homersimpson – 2016-04-18T00:48:24.263

2@LudovicFrérot Actually, these are not ideograms, these are chinese english letters. – Erik the Outgolfer – 2016-07-01T08:29:17.037

Answers

30

Jelly, 5 3 2 bytes

Thanks to Dennis for saving 2 bytes. Also thanks to FryAmTheEggman for saving 1 byte. Code:

p⁶

Explanation:

p⁶   # Cartesian product with the input and the space character.

Uses the Jelly encoding.

Try it online!

Adnan

Posted 2016-03-22T17:45:18.033

Reputation: 41 965

You don't need s1. – Dennis – 2016-03-22T17:54:49.950

@Dennis Oh thanks! I didn't know that. – Adnan – 2016-03-22T17:56:04.307

1⁶ takes up three bytes in UTF-8. – Jess Smith – 2016-03-22T18:02:25.300

12

@JessSmith Jelly uses its own code page: https://github.com/DennisMitchell/jelly/blob/master/docs/code-page.md

– a spaghetto – 2016-03-22T18:02:56.323

1@AandN Put it in the answer, not a comment. – mbomb007 – 2016-03-22T20:08:53.357

3@mbomb007 It's right in the header. – Adnan – 2016-03-22T20:09:18.833

5@AandN No, you should say in your answer that it has its own code page. Especially since it's a newer language, so people don't know yet. – mbomb007 – 2016-03-22T20:10:59.833

Woah, that was fast! (Also, should the 6 be two bytes since it's Unicode?) – ASCIIThenANSI – 2016-03-24T00:15:39.153

1

@ASCIIThenANSI Jelly uses it's own custom encoding.

– Adnan – 2016-03-24T15:14:11.663

@AandN OK, thanks! – ASCIIThenANSI – 2016-03-24T15:17:14.103

Doesn't this take input from the command-line arguments rather than STDIN? – Esolanging Fruit – 2017-06-04T16:19:21.127

@Challenger5 Fixing it is trivial: ɠp⁶ – Erik the Outgolfer – 2017-06-04T20:17:21.807

For the record, the atom K was added on Aug 12 '16, later than the challenge, that does exactly what the challenge asks for. – user202729 – 2018-01-17T08:26:50.013

Invalid because it doesn't use STDIN. – pppery – 2019-08-19T17:29:07.730

24

Python 3.5, 18 bytes

print(*input(),'')

This works because print's default separator is single space.

vaultah

Posted 2016-03-22T17:45:18.033

Reputation: 1 254

3print(*input(),end=' ') would be portable, but it's not very golfy... – Dennis – 2016-03-22T20:35:36.640

9MFW the first use of my PEP I see in the wild is on Code Golf. – Veedrac – 2016-03-23T08:15:54.263

Does this have a space after the last character? – Esolanging Fruit – 2017-06-04T16:15:14.913

17

Hexagony, 21 13 12 10 bytes

Code:

Saved a lot of bytes thanks to FryAmTheEggman. Code:

P,<0/*;@.>

Or in a more readable form:

  P , <
 0 / * ;
@ . > . .
 . . . .
  . . .

Try it online!

Explanation:

The Hexagony program starts at the top-left corner, immediately setting the memory edge to the ASCII value of P, which is 80. After that, we can see that the following path is taken:

enter image description here

We can see that the path taken is: P,<;.P/0....;*/>. After the P, we take a byte of user input. If this is empty, the following branch (<) would direct us to the North East. If the input is non-empty, the branch directs us to the South East. After that, we output the user input using ;. We set the memory edge back to P, which is 80. The zero followed by the mirror is then concatenated to our number, resulting into 800. This is then outputted using the ; command, but first it is taken modulo 256, resulting into 32, which is the space character. After that, we reset the memory edge using the * command and return to loop over the rest of the user input. When we're done with the user input, the path is directed to the North East:

enter image description here

This basically goes to the @ command, which terminates the program.

Using Timwi's amazing HexagonyColorer for making the diagrams.

Adnan

Posted 2016-03-22T17:45:18.033

Reputation: 41 965

Uh, I was golfing while you edited. Oops. 10: P,<0/*;@.> – FryAmTheEggman – 2016-03-22T19:33:39.270

@FryAmTheEggman Hahaha, let's make a new explanation then :p. – Adnan – 2016-03-22T19:39:20.277

P,<<>0;@>* is also 10, but unfortunately I don't think it helps in shaving off another byte. – Martin Ender – 2016-03-23T06:54:12.003

@MartinBüttner Oh, that's a shame. I doubt if it's possible to shave off another byte, but it seems unlikely. – Adnan – 2016-03-24T16:03:51.870

Is HexagonyColorer now animated? – Esolanging Fruit – 2017-06-04T16:15:38.300

13

Haskell, 11 bytes

((:" ")=<<)

Usage example: ((:" ")=<<) "Code Golf" -> "C o d e G o l f ".

Map each character c to a two element list [c, space] and concatenate everything into a single list.

nimi

Posted 2016-03-22T17:45:18.033

Reputation: 34 639

Interesting that Haskell and Jelly are kind of doing the same thing here, since the list monad acts similarly to a Cartesian product. – ballesta25 – 2016-03-24T05:43:42.187

9

Retina, 5

.
$& 

Note the space at the end of the second line.

$& is equivalent to $0. Thanks to @mbomb007 for this link.

Try it online.

Digital Trauma

Posted 2016-03-22T17:45:18.033

Reputation: 64 644

@FryAmTheEggman I prefer to use $0. It's the same thing, but more common. – mbomb007 – 2016-03-22T19:42:44.080

Here's a useful reference to go along with Retina's wiki: https://msdn.microsoft.com/en-us/library/ewy2t5e0(v=vs.110).aspx#EntireMatch

– mbomb007 – 2016-03-22T19:45:09.373

6

JavaScript, 20 Bytes

Simple, I just wish that Array.join added the space to the end so I could save 3 bytes.

s=>[...s,``].join` `

Generic User

Posted 2016-03-22T17:45:18.033

Reputation: 373

5[...s,``].join` ` perhaps? – Neil – 2016-03-22T18:39:30.240

3Even better [...s,,].join ... – edc65 – 2016-07-01T13:27:21.333

@edc65 Doesn't work in latest Firefox or Chrome? I just get the join function as the return, as I would expect. – Mwr247 – 2016-07-01T15:55:42.853

@Mwr247 after the join you must put the rest of your code, that's why I put ellipsis (...). It's just 1 byte saving – edc65 – 2016-07-01T23:45:40.613

@edc65 may have been too lazy to work out how to type the \ `` in a comment. – Neil – 2016-07-09T21:11:57.447

(mobile can’t paste?) 19 bytes: s=>[...s,,].join `` – Stan Strum – 2018-01-11T17:47:03.270

5

Java, 132 (System.in) or 99 (Program argument) bytes

Can you feel the overhead tonight?

class F{public static void main(String[]a){System.out.print(new java.util.Scanner(System.in).nextLine().replaceAll("(.)", "$0 "));}}
class W{public static void main(String[]a){for(char c:a[0].toCharArray())System.out.print(c+" ");}}

shooqie figured out a 6 byte shorter way to do this but I won't steal their approach. I've used it with the STDIN and lambda versions, however.

28 characters for a lambda but that doesn't meet the program requirement.

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

CAD97

Posted 2016-03-22T17:45:18.033

Reputation: 1 367

The question specified that the input must be from STDIN. – EMBLEM – 2016-03-22T20:17:02.470

I could add one for you, if that's ok. – Blue – 2016-03-22T21:26:50.830

I've added a STDIN version now (and used the clever regexplace shooqie figured out). – CAD97 – 2016-03-23T01:47:07.267

No need for parentheses in your regex. Also removed an extra space between arguments to replaceAll. – Khuldraeseth na'Barya – 2019-08-19T15:53:11.403

5

><>, 13 10 bytes

3 bytes saved thanks to @Sp3000

i:0(?;o 'o

Try it here. Click the link, then Submit, then type some input and press Give, and finally run the program with Start or Run without animation.

Explanation

i       read a character
:       duplicate
0(      is it less than 0?
?;      if so: end program. Else:
o       output read character
 '      push all chars until matching (same) quote. Top character is a space
o       output that character, which is a space. Go back to the beginning

Luis Mendo

Posted 2016-03-22T17:45:18.033

Reputation: 87 464

i:0(?;o 'o for 10 – Sp3000 – 2016-03-23T01:51:13.307

In fact, io 'o works too, erroring out. – Sp3000 – 2016-03-23T01:52:36.420

@Sp3000 Thanks! I'll go for the no-error version (maybe you want to submit yours?). I forgot you can input chars directly. How does the unmatched quote work? Does it always pick the preceding char? – Luis Mendo – 2016-03-23T01:56:08.767

1' just wraps around, pushing chars until it finds another ' to close it. In this case the opening and closing 's are the same char and most of the source code is pushed, but the top char would just be space since it was pushed last. – Sp3000 – 2016-03-23T01:57:34.197

@Sp3000 Got it. So that's also cyclical. Thanks a lot for the suggestion and explanation! – Luis Mendo – 2016-03-23T01:58:27.187

My first ><> answer! – Luis Mendo – 2016-03-23T02:02:28.910

@CAD97 This is one of those cases where there's a discrepancy between fishlanguage.com and the official Python interpreter (which @Dennis has kindly added to Try it online!). In the official Python interpreter, trying to output a char with a negative code point terminates with an error.

– Sp3000 – 2016-03-23T02:05:04.923

Context please? – CalculatorFeline – 2016-03-23T02:33:01.430

@CatsAreFluffy I had a comment for about 15 seconds saying that the online interpreter printed -1 as the char 0xFF instead of terminating. I deleted the comment because SE didn't show the character I copy/paste'd. – CAD97 – 2016-03-23T02:49:48.973

4

Cubix, 9 bytes

@./.i?>So

See it work online!

Cubix is a language in which the instructions are mapped out onto the face of a cube. This program forms the following cube net:

    @ .
    / . 
i ? > S o . . .
. . . . . . . .
    . .
    . .

The instruction pointer begins at i, which takes another character-code from input and pushes it to the stack. If there is no more input left to be taken, the ? turns the IP left, where it hits /, and is reflected upwards to @, which terminates the program.

However, if there is input left, the value will be a character code. As all1 character codes are positive, the ? makes the IP turn right, where it wraps all the way around the cube, passing o on the way which outputs the char. It then hits / which makes it loop back around to >So, which pushes and prints a space. The IP carries on west until wrapping around back to the i, back to the start of the main loop.

1 If the character is a null byte, it will ignore the ? and carry on straight ahead, simply outputting a single space.


Of course, there's only so much a written explanation can do, so I highly recommend you view this in the online interpreter. There's a "speed" option, which allows you to view the execution as slow or fast as you like.

FlipTack

Posted 2016-03-22T17:45:18.033

Reputation: 13 242

1you can save a byte with @.Uoi?So – MickyT – 2017-07-03T22:07:49.777

4

Stax, 2 bytes

Ties Jelly!

0\

Try it at staxlang.xyz!

All this does is push 0 to the stack and zip the string from standard input with it, repeating the 0 as necessary. In Stax, code point 0 in a string is usually converted to 32 (space).

This is short enough that packing it into ûT does nothing but reduce readability.

Khuldraeseth na'Barya

Posted 2016-03-22T17:45:18.033

Reputation: 2 608

4

Cubix, 10 bytes

Cubix is a 2 dimensional language developed by @ETHproductions where the commands are wrapped onto a cube. Try it online

@.?wi^\oSo

This maps onto a cube with edge length 2

    @ .
    ? w
i ^ \ o S o . .
. . . . . . . .
    . .
    . .

Starts with a input i. The flow is redirected north ^ to the top face. ? If the value is negative turn left to finish @, zero carries on into shift right w or positive turn right then reflect left \. Output character with a trailing space oSo.

MickyT

Posted 2016-03-22T17:45:18.033

Reputation: 11 735

3

Threead, 45 16 Bytes non-competing.

  B[coB]
32c   o

Takes input via STDIN.

The first Line/Tape simply reads bytes from STDIN, and writes them. The second line, initially stores a space via 32c, then at the same time that the next character is being read, outputs that space.

Try it online!

ATaco

Posted 2016-03-22T17:45:18.033

Reputation: 7 898

3

PHP, 31 bytes

<?=chunk_split($argv[1],1," ");

takes input from command line argument.

Titus

Posted 2016-03-22T17:45:18.033

Reputation: 13 814

3

MATL, 7 bytes

tnZ"v1e

Try it online!

Explanation

t    % implicitly take input string and duplicate it
n    % number of elements
Z"   % string with that many spaces
v    % concatenate vertically (2xN array, where N is input length)
1e   % reshape into 1 row. Implicitly display

Luis Mendo

Posted 2016-03-22T17:45:18.033

Reputation: 87 464

3

05AB1E, 4 bytes

Sð«J

Try it online.

Explanation

Sð«J

S     split string into a list
 ð«   append a space to each element
   J  join

a spaghetto

Posted 2016-03-22T17:45:18.033

Reputation: 10 647

ðâJ non-competing. – Magic Octopus Urn – 2017-01-12T16:03:00.643

Another 3-byte alternative: Sðý

– Kevin Cruijssen – 2019-02-11T10:48:00.283

3

Gema, 5 bytes

?=?\ 

Sample run:

bash-4.3$ gema '?=?\ ' <<< 'Full width text.'
F u l l   w i d t h   t e x t . 

manatwork

Posted 2016-03-22T17:45:18.033

Reputation: 17 865

I haven't seen this language before. Link to the interpreter? – a spaghetto – 2016-03-26T04:57:55.663

Sorry. Added hyperlink to the post title. Quite old, but sadly, Google can efficiently help finding it only if you know that the name comes from “general purpose macro processor”. – manatwork – 2016-03-26T13:52:44.940

3

CJam, 5 4 bytes

1 byte fewer thanks to @FryAmTheEggman

lSf+

Try it online!

Explanation

l     e# read line
Sf+   e# map "concatenation" (+) with a space (S) as extra parameter
      e# implicitly display characters in the stack

Luis Mendo

Posted 2016-03-22T17:45:18.033

Reputation: 87 464

3

GolfScript, 6 bytes

' ':n*

Try it online!

Dennis

Posted 2016-03-22T17:45:18.033

Reputation: 196 637

3

Awk, 7 bytes

(4 characters code + 3 characters command line option.)

NF++

Sample run:

bash-4.3$ awk -F '' 'NF++' <<< 'Full width text.'
F u l l   w i d t h   t e x t . 

(There is some disagreement on what should be included in the command line option count. I included what is actually passed to the awk interpreter: “-”, “F” and a separator between “F” and the empty string parameter. See below what I mean.)

bash-4.3$ od -tax1 /proc/`pidof awk`/cmdline 
0000000   a   w   k nul   -   F nul nul   N   F   +   + nul
         61  77  6b  00  2d  46  00  00  4e  46  2b  2b  00
                         ╰────────╯

manatwork

Posted 2016-03-22T17:45:18.033

Reputation: 17 865

3

C, 56 Bytes (as program argument), 46 Bytes (from stdin)

main(int a,char**b){while(*b[1])printf("%c ",*b[1]++);}

Plain old C answer. Once compiled, the program needs to be called with a string as it's first parameter, a string with spaces needs to be enclosed in quotes. For the example in the start post:

./prog "Full width text is text that has a space after every character, including the last one."

Which will output

F u l l   w i d t h   t e x t   i s   t e x t   t h a t   h a s   a   s p a c e   a f t e r   e v e r y   c h a r a c t e r ,   i n c l u d i n g   t h e   l a s t   o n e .

Solution that reads directly from stdin.

main(c){while(c=~getchar())printf("%c ",~c);}

One byte less thanks to @FryAmTheEggman

SBI

Posted 2016-03-22T17:45:18.033

Reputation: 211

The requirements are a little murky, but I believe you have to read the input from stdin rather than taking it as an argument. Also, here is a page with some useful tips for further golfing in C: http://codegolf.stackexchange.com/q/2203/13877

– Josh – 2016-03-22T19:59:40.010

@Josh Does it count as a parameter to main? Because otherwise, the Java answer will be just as wrong, and not so sure about the Haskell one either. – SBI – 2016-03-22T20:04:08.350

Either is fine we like our I/O to be friendly :) But I do believe using getchar() is shorter. Also you don't need the include for most C compilers. – FryAmTheEggman – 2016-03-22T20:06:31.740

@FryAmTheEggman I left the include in to be completely compliant, I can only test with gcc. As long as gcc-only is fine, yeah, shaving the include is alright. – SBI – 2016-03-22T20:10:14.633

Generally, if it works with Ideone it's ok :)

– FryAmTheEggman – 2016-03-22T20:12:38.660

@FryAmTheEggman How about non terminating? Because that's the only way a getchar version will be shorter. That sort of stops to count as a proper program for me :D – SBI – 2016-03-22T20:13:41.993

Really? I think I have a shorter way with getchar, but generally no that's not alright unless specifically allowed. – FryAmTheEggman – 2016-03-22T20:14:58.860

I'm an idiot, that's all. – SBI – 2016-03-22T20:15:36.643

Your non terminating answer can be made to terminate by adding ~ before cs assignment and usage, to convert EOF to 0. – FryAmTheEggman – 2016-03-22T20:21:13.440

Languages are defined by their implementation on PPCG. If it works without the include statement (and it does with GCC), you don't need it. – Dennis – 2016-03-22T20:38:21.967

@FryAmTheEggman I realised just as I hit edit, but somehow my latest edit reverted instead of adding the functioning version. Hence my comment about being an idiot ;) Dennis, thanks for the clarification. – SBI – 2016-03-22T20:47:03.440

You can save some bytes with main(a,b)char**b;{...} – Cyoce – 2017-03-04T21:52:34.200

3

brainfuck, 24 22 bytes

Simple example using the shortest known 32 for the space character(s).

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

Try it online

mbomb007

Posted 2016-03-22T17:45:18.033

Reputation: 21 944

,[.>>-[-[-<]>>+<]>-.,] saves two bytes. – Dennis – 2016-07-01T22:15:56.033

3

Java, 92

class T{public static void main(String[]A){System.out.print(A[0].replaceAll("(.)","$0 "));}}

shooqie

Posted 2016-03-22T17:45:18.033

Reputation: 5 032

3

R, 36 bytes

cat(strsplit(readline(),"")[[1]],"")

Example:

> cat(strsplit(readline(),"")[[1]],"")
Hello R!
H e l l o   R ! 

lambruscoAcido

Posted 2016-03-22T17:45:18.033

Reputation: 401

1

You don't need sep=" ", so this can be much shorter: Try it online!

– Giuseppe – 2018-03-09T16:50:13.467

3

WhoScript 38 bytes

1v;pr;e;#0 1;-;i;t=;ti;o;tl;" ";d;>;pf

Works best when the string is given at the command line, but it can be done one character at a time in real time as well.

Ungolfed:

time_vortex
  psychic_paper read
  duplicate
  # 0 1
  -
  integer
  TARDIS =
  TARDIS if
      opening
  TARDIS landing
  # 20
paradox
pop
psychic_paper flush

MCS-Kaijin

Posted 2016-03-22T17:45:18.033

Reputation: 109

3

PHP, 39 bytes

echo join(' ',str_split($argv[1])).' ';

Run it from the command line

php fullwidth.php "Full width text is text that has a space after every character, including the last one."

https://eval.in/541179

ʰᵈˑ

Posted 2016-03-22T17:45:18.033

Reputation: 1 426

3

Labyrinth, 10 bytes

<.23.%):,>

This terminates with an error, but the error messages goes to STDERR.

Try it online!

Explanation

This is one of the rare cases where a completely linear program is feasible. The loop is achieved via the source code modification commands < and >, which works because after each iteration we know that the stack is empty again.

< cyclically shifts the entire line one cell to the left, so we end up with:

.23.%):,><

This takes the instruction pointer (IP) with it so the IP is now at the right end of the code and has to move left. Next, the > does the opposite modification so it shifts the source code back to

<.23.%):,>

Now we execute a single iteration (from right to left), before everything starts over:

,    Read a character code from STDIN, or -1 at EOF.
:)   Duplicate and increment.
%    Modulo. At EOF this will attempt a division by zero and terminate. Otherwise, we
     have n % (n+1) = n, so we're left with the input character again.
.    Print it back to STDOUT.
32   Turn the top of the stack into a 32.
.    Print it as well (a space).

Martin Ender

Posted 2016-03-22T17:45:18.033

Reputation: 184 808

3

C, 50 bytes

Little bit of main() recursion :)

main(c){~(c=getchar())?printf("%c ",c),main():0;}

Try it online! - If using this on your own machine, use Ctrl+D to signify EOF.

homersimpson

Posted 2016-03-22T17:45:18.033

Reputation: 281

3

Python 2, 27 25 24 bytes

lambda x:' '.join(x)+' '

Shorter than Raffi's answer...

-1 thanks to 60919 (FlipTack).

Erik the Outgolfer

Posted 2016-03-22T17:45:18.033

Reputation: 38 134

If functions are allowed then lambda x:' '.join(x)+' ' is 1 byte shorter. – FlipTack – 2017-01-12T20:06:15.387

3

APL, 5 bytes

∊2∘↑¨

This takes 2 items for each character in the string, with the effect of adding a space

To make it a program that takes stdin, it's the same number of bytes:

∊2↑¨⎕

Try it here.

Moris Zucca

Posted 2016-03-22T17:45:18.033

Reputation: 1 519

2

Carrot, 13 bytes, non-competing

#^//./gS" "^ 

(note trailing space in code)

Try it online!

(to be able to see the trailing space in the output, open up the JS console and select the outputted text in the console output)

Explanation

Note: the "stack" is actually just a string (not an array) in Carrot

#^                        // pushes the input `#` to the stack, now the stack == input
  /                       // split on:
   /./g                   //  every character in the stack

Now the program is in arrayMode, meaning that the stack is now an array (or stackA to be more precise)

       S" "               // join on spaces

Now we got spaces after every character except for the last one

           ^<space>       // append a space to the stack

And then the stack is implicitly outputted

user41805

Posted 2016-03-22T17:45:18.033

Reputation: 16 320

I just accidentally posted this solution without seeing yours. Is there no way to convert to array mode with A by splitting on nothing so Hi becomes [ "H", "i" ]? I though no argument would do it or a space but I was wrong. – TheLethalCoder – 2017-07-26T16:26:18.247

@TheLethalCoder Another one of the reasons I am doing the rewrite of Carrot, the current interpreter does a terrible job of parsing and everything is just a bunch of hacks taped very loosely... In the new interpreter, A is planned take a string as an argument, where this string can be of any length, in which case what you are suggesting should work. – user41805 – 2017-07-26T16:36:32.450

2

C++ (gcc), 120 133 77 bytes

#import<iostream>
int main(){char c;while(std::cin.get(c))std::cout<<c<<" ";}

Thanks to my father, who showed me a nifty trick for getting the characters directly from the input stream... and in turn almost halfed my byte count!

Old solution below using getline and joining substrings:

#import<iostream>
int i;int main(){std::string s,n;std::getline(std::cin,n);for(;i<n.size();i++){s+=n.substr(i,1)+" ";}std::cout<<s;}

Try it Online!

My very first try on golfing. Feel free to give suggestions.

TheOutrageousZ

Posted 2016-03-22T17:45:18.033

Reputation: 21

Oh well, that's embarassing. I wrote the same amount of bytes as another answer and that one has got five downvotes. Oops. – TheOutrageousZ – 2017-12-14T15:50:27.090

2

Welcome to PPCG! I don't know C, but this fails on words with spaces TIO

– FantaC – 2017-12-14T15:53:44.520

@tfbninja Fixed. cin isn't particularly fond of strings containing spaces. – TheOutrageousZ – 2017-12-14T17:28:34.590

2

K (ngn/k), 10 bytes

{,/x,'" "}

Try it online!

(Ignored the stdin constraint. Let me know if I should delete, am new to SE)


EDIT: i made a mistake WRT stdin functionality in k. thanks, @ngn, for the correction:

K (ngn/k), 18 bytes

{1@,/(0:""),'" ";}

Try it online!


k4, 12 bytes

,/(0:0),'" "

which looks like:

 ,/(0:0),'" "
full-width text
"f u l l - w i d t h   t e x t "

scrawl

Posted 2016-03-22T17:45:18.033

Reputation: 1 079

Unless ngn/k is completely incapable of taking input any other way, you are not allowed to take input by adding it to your source code, even ignoring this challenge's explicit requirement to use STDIN. – pppery – 2019-08-19T16:23:01.450

@pppery there is no stdin functionality within k – scrawl – 2019-08-19T17:23:23.777

10:"" reads from stdin – ngn – 2019-08-20T15:13:37.030

@ngn TIL... i will update. thanks! – scrawl – 2019-08-20T15:16:54.737

by the way, it's `0:`` in k7 (shakti), i'll add that as an alternative next time i update ngn/k – ngn – 2019-08-20T15:20:02.467

@ngn thank you for the info. it's really appreciated. question: is 0:"" ngn/k-compatible only? the above breaks in k4 (i do most of my work in k4 and adapt to ngn/k as necessary to provide a TIO link). – scrawl – 2019-08-20T15:25:02.993

it was in k6 before it got abandoned. the one-page summary at kparc had this in it: 0:""0:"prompt" /readline writeline (well, it's not exactly the same. i assumed empty filename means stdin.) – ngn – 2019-08-20T15:37:54.767

@ngn got back to this today. in k4 0:0 will read (0:) from console which is handle 0. thanks for showing me this, i hadn't encountered stdin in q/k before! – scrawl – 2019-08-22T11:09:53.117

2

naz, 50 42 bytes

2a2x1v1x1f0a0x1x2f1r3x1v1e1o0m8a4m1o2f0x2f

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

Edit: Saved 8 bytes by condensing the code into 2 functions instead of 3.

Explanation (with 0x commands removed)

2a2x1v                   # Set variable 1 equal to 2
1x1f0a                   # Function 1
                         # Add 0 to the register
1x2f1r3x1v1e             # Function 2
                         # Read a byte of input
                         # Jump to function 1 if it equals variable 1
            1o0m8a4m1o2f # Otherwise, output it, output 32 (space),
                         # then jump back to the start of function 2
2f                       # Call function 2

The only way for a naz program to know when to stop reading its input is to give it a special case to check for, in this case STX.

sporeball

Posted 2016-03-22T17:45:18.033

Reputation: 461

2

Pyth, 5 4 bytes

Thanks to @FryAmTheEggman for saving a byte.

s*zd

Try it online here.

Maltysen

Posted 2016-03-22T17:45:18.033

Reputation: 25 023

Jesus hecking christ how the heck – Tornado547 – 2017-12-14T19:53:39.863

Alternative 4-byter: s+R; – Sok – 2019-02-14T13:56:56.910

2

Seriously, 7 bytes

' ;,@j+

Try it online!

Man, that required ending space added 3 additional bytes. Without it, ,' j would work for 4.

Explanation:

' ;,@j+
' ;      push two copies of a single space
   ,@    push input, swap
     j+  join on spaces, append a space

Mego

Posted 2016-03-22T17:45:18.033

Reputation: 32 998

2

Pyke, 5 bytes

dm+s_

Explanation:

d     -    load ' ' onto the stack
 m+   -   map(add, eval_input_or_not(), " ")
   s  -  "".join(^)
    _ - ^[::-1]

At the moment Pyke has a bug where if map is given a string, it reverses it :(

Or with a new fixed version, 3 bytes

dL+

Try it here!

left_map(input(), " ", add)

Blue

Posted 2016-03-22T17:45:18.033

Reputation: 26 661

2

Ruby, 24 15 bytes

gsub /./,'\0 '

Requires the -p flag (byte added).

Thanks to xsot for 9 bytes!

Doorknob

Posted 2016-03-22T17:45:18.033

Reputation: 68 138

Using -p saves 8 bytes – xsot – 2016-03-23T01:03:54.830

@xsot Thanks, I didn't even know that flag existed! – Doorknob – 2016-03-23T01:10:02.303

I didn't realise you could omit the parentheses without confusing the interpreter. Looks like the comma operator isn't as overloaded the way I expected. – xsot – 2016-03-23T01:28:07.423

1@xsot Comma's not an operator in Ruby. Parenthesis are frequently optional, except in certain contexts. – Doorknob – 2016-03-23T01:29:31.707

2

Labyrinth, 11 bytes

32@
 :,
 ..

This is an 11-byte answer which terminates without an error – see @MartinBüttner's answer for a 10-byte answer which terminates with an error. Try it online!

Starting from the top-left, we have the following setup step:

32        Turn a zero at the bottom of the stack into 32 (space)

Then we turn right at the 2, entering the following tight loop:

:          Duplicate top of stack (space)
,          Read char from STDIN
.          Output char
.          Output space

This loop repeats until , reads EOF, which pushes -1 to the top of the stack. The -1 makes us turn left into the @, terminating the program.


Here are two additional error-free 11-byte solutions, by Martin:

Extra version A

  3
.:2
.,@

This version is the same as the above, but rotated 90 degrees. We still start on the 3, since this is the first valid instruction in reading order.

Extra version B

^,.
@:.
2
3

This version is effectively the same as the previous two, but uses an initial ^ to rotate the first column upon running the program, such that the board becomes:

@,.
2:.
3
^

After this, the code is the same as the original, except rotated 90 degrees in the other direction.

Sp3000

Posted 2016-03-22T17:45:18.033

Reputation: 58 729

2

Befunge-93, 12 bytes

~:1+!#@_, ",

Tested using this online interpreter.

~                           Read char
 :1+!                       Push (char == -1)
     #@_                    Halt if so, i.e. on EOF
        ,                   Output char
          "~:0`!#@_, "      Push the chars between the quotes, one by one
                      ,     Output the top char, i.e. space

Sp3000

Posted 2016-03-22T17:45:18.033

Reputation: 58 729

Wow, sleek usage of " and wrap-around – daniero – 2016-03-23T18:21:54.573

-1 Byte – Jo King – 2017-12-19T07:32:17.583

2

Sed, 8 bytes

's/$*/ /g'

Can be run from bash as

$ sed 's/$*/ /g' <<< "Full Width Text."

Outputs

 F u l l   w i d t h   t e x t .

Ben Perlin

Posted 2016-03-22T17:45:18.033

Reputation: 69

Nice answer, but i think you mean '/g/ in the test case not '/f'. +1 though. – Rɪᴋᴇʀ – 2016-03-24T02:47:22.993

Thank you, 'f' is right next to 'g' on the dvorak keyboard – Ben Perlin – 2016-03-24T03:37:11.570

My understanding is that a leading space is not permitted. – Neil – 2016-03-24T10:55:00.317

2

beeswax, 20 bytes

p?Cy ?<~1V_
>` `Ag'b

Example:

julia> beeswax("Full Width Text.bswx")
sHello, World!
H e l l o ,   W o r l d !
Program finished!

Explanation:

             lstack    gstack

          _  [0,0,0]•  []•                          create bee
         V   [0,0,0]•  [72,101,108,108,111,10]•     read in string to gstack
        1    [0,0,1]•                               lstack 1st=1
       ~     [0,1,0]•                               flip lstack 1st and 2nd
      <      [0,0,0]•                           (1) redirect to left
     ?       [0,1,0]•  [72,101,108,108,111]•        pop gstack top value (\n)
   y         [0,1,0]•  [101,108,108,111,72]•        rotate gstack down by lstack[-,steps,depth]•
                                                    depth=0 defaults to full stack length
  C                    STDOUT='H'                   print gstack top value as Char to STDOUT
 ?                     [101,108,108,111]•           pop gstack top value
p                                                   redirect to lower left
>                                                   redirect to right
 ` `                   STDOUT=' '                   print space char to STDOUT
    A                  [101,108,108,111,4]•         push gstack length on top of gstack
     g       [0,1,4]•                               lstack 1st=gstack top
      '                                             skip next if lstack 1st=0
       b                                            redirect to upper left
      <                                             loop back to (1)
     ?                 [101,108,108,111]•
   y         [0,1,4]•  [108,108,111,101]•
  C                    STDOUT='e'
 ?                     [108,108,111]•
p
>` `                   STDOUT=' '

.                          .                             .
.                          .                             .
.                          .                             .

M L

Posted 2016-03-22T17:45:18.033

Reputation: 2 865

2

MATL, 7 bytes

32HY(1e

Try it Online!

Explanation

    % Implicitly grab input as a string
32  % Number literal (ASCII for ' ')
H   % Clipboard H contains 2 by default
Y(  % Fill the second "row" with spaces
1e  % Force everything onto one row. Due to MATLAB being row-major, this inserts the spaces
    % Implicitly display the result

Suever

Posted 2016-03-22T17:45:18.033

Reputation: 10 257

2

Hoon, 41 bytes

|*
*
`tape`(turn +< |=(@ (cat 3 +< ' ')))

Takes advantage of not having to specify the tape of a wet gate (|*), and that arguments are places at +< to prevent having to name them.

There are actually two different types of strings in Hoon: tapes, and cords. tapes are (list @tD), while cords are simply @t. Think the difference between a vector and an array: tapes can be indexed into and manipulated easily, while cords are "static" and basically just bignums.

This entry maps over the characters in the tape it gets as input, and adds on the value of ' ' to the end of the atom and then casts the result back to a tape.

Technically, this should probably be a type error: tape is a list of characters, and we are stuffing two in the space of only one. Luckily, while Hoon has syntax to say what you should expect the size of an atom to be, it doesn't actually enforce that expectation. Even slamming a too-big atom with a specific sized verification gate doesn't give back the default value like it should. Naturally, we abuse this and it even prints correctly in the console, as long as you don't try to full-width text any UTF-8 characters.

Usage:

> %.  "Full width text is text that has a space after every character, including the last one."
  |*
  *
  `tape`(turn +< |=(@ (cat 3 +< ' ')))
"F u l l   w i d t h   t e x t   i s   t e x t   t h a t   h a s   a   s p a c e   a f t e r   e v e r y   c h a r a c t e r ,   i n c l u d i n g   t h e   l a s t   o n e . "

RenderSettings

Posted 2016-03-22T17:45:18.033

Reputation: 620

2

C#, 137 bytes

Func<string,string>f=(a)=>{return string.Concat(a.ToCharArray().SelectMany(x=>(new char[] {' '}),(x, y)=>x.ToString()+y.ToString()));};

doing a console on it gives result : Console.WriteLine(f("arnab bhattacharya")); a r n a b b h a t t a c h a r y a

Arnab Bhattacharya

Posted 2016-03-22T17:45:18.033

Reputation: 21

It's been a while since I've used C#, but I don't believe you need the Func<string,string>f= part - we allow anonymous functions, so long as they can be captured and called. – Mego – 2016-07-01T10:18:02.447

@Mego I think he needs to provide datatypes, and he cannot provide them otherwise. – Erik the Outgolfer – 2016-07-01T10:28:10.307

1

You should read the C# golfing tips thread. :)

– aloisdg moving to codidact.com – 2016-07-06T18:48:37.267

1

tcl, 41

puts [regsub -all (.) [gets stdin] \\1\ ]

on http://rextester.com/KCIB63188

sergiol

Posted 2016-03-22T17:45:18.033

Reputation: 3 055

Just noticed now, there was another Tcl answer! – sergiol – 2017-01-12T03:20:47.823

1

C 55, 49 bytes

g(){c;while((c=getchar())!='\n')printf("%c ",c);}

Ungolfed version:

void g()
{
  char c;
  while((c=getchar())!='\n')
  printf("%c ", c);
}

Abel Tom

Posted 2016-03-22T17:45:18.033

Reputation: 1 150

1

TI-84 BASIC, 44 bytes

Pretty straightforward approach:

Input Str1
sub(Str1,1,1
For(A,2,length(Str1
Ans+" "+sub(Str1,A,1
End
Ans+" 

The only size optimizations I could come up with were:

  • leaving off closing quotes and parentheses at the end of lines
  • using Ans instead of a string variable (the Ans token is 1 byte, StrN are 2, and assignment to Ans is implicit)
  • printing the result by placing it on the last line of the program (no Disp command needed)

This program wouldn't work correctly for an empty input string, since it unconditionally stores the first character of Str1 in Ans. (This is necessary because concatenation with an empty string raises an error!) Fortunately, the Input command doesn't accept an empty string in the first place.

The size calculation was informed by TI-Basic Developer's token size charts.

Jakob

Posted 2016-03-22T17:45:18.033

Reputation: 2 428

1

OIL, 52 49 bytes noncompeting

Note: The second line contains a space character.

5

12
0
23
10
24
3
7
10
4
24
4
1
8
11
1
11
6
6
5

I explode the input string, then print each character and then a space.

L3viathan

Posted 2016-03-22T17:45:18.033

Reputation: 3 151

1

Pushy, 7 bytes

Note that this answer is non-competing as the language postdates the challenge.

32DL:{'

Try it online!

Works like so:

       \ Implicit: Input is on stack as charcodes
32D    \ Set the printing delimiter to a space
L:     \ Input length times do:
  {    \   Cyclically shift the stack left
   '   \   Print the last character (includes trailing space)

Alternatively, for the same byte count, one could have:

L:{32;"

Try it online!

L:   ;   \ Length times do:
  {      \   Shift string left
   32    \   Insert char 32 (a space)
      "  \ Afterwards, print the whole string

FlipTack

Posted 2016-03-22T17:45:18.033

Reputation: 13 242

1

Japt, 4 bytes

U®+S

Non-competing 3-byte answer:

®+S

Try it online!

Oliver

Posted 2016-03-22T17:45:18.033

Reputation: 7 160

1

Lua, 57 bytes

t=""io.read():gsub(".",function(c)t=t..c.." "end)print(t)

Josh

Posted 2016-03-22T17:45:18.033

Reputation: 1 021

1

SmileBASIC 3, 44 bytes

INPUT A$FOR I=0TO LEN(A$)-1?A$[I]+" ";
NEXT

This doesn't leave a new line after the output, so from direct you might get

?HELLO
H E L L O OK

but hopefully it's not an issue.

snail_

Posted 2016-03-22T17:45:18.033

Reputation: 1 982

You can make the loop shorter by doing: WHILE""<A$?SHIFT(A$);" ";:WEND – 12Me21 – 2017-04-21T14:17:40.643

1

C#, 52 bytes

Manual, straightforward approach, without using Linq.

s=>{var r="";foreach(var c in s)r+=c+" ";return r;};

Anonymous method which gets every character from the string and adds a space after each one.

Full program:

using System;

namespace FullWidthText
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string, string> f =
            s =>
            {
                var r = "";
                foreach (var c in s)
                    r += c + " ";
                return r;
            };

            Console.WriteLine(f("Full width text is text that has a space after every character, including the last one."));
        }
    }
}

adrianmp

Posted 2016-03-22T17:45:18.033

Reputation: 1 592

1

Vim, 12 10 keystrokes

:s/./& /g<CR>

1 byte longer:

qqa <Esc>l@qq@q

-2 bytes thanks to @KritixiLithos

BlackCap

Posted 2016-03-22T17:45:18.033

Reputation: 3 576

You don't need to delete the last space and :s/./\0 /g<CR>$x can become just :s/./& /g<CR> at 10 bytes. – user41805 – 2017-06-05T04:05:26.157

1

q/kdb+, 12 bytes

Solution:

raze{x,'" "}

Example:

q)raze{x,'" "}"Hello World!"
"H e l l o   W o r l d ! "

Explanation:

,'   / join (,) each left ("H", "e", "l"...) with each right (" ")
raze / reduce list

Notes:

Would be 9 bytes doing it more directly rather than as a lambda function:

q)raze"Hello World!",'" "
"H e l l o   W o r l d ! " 

streetster

Posted 2016-03-22T17:45:18.033

Reputation: 3 635

1

Javascript, 16 bytes

[...s,,].join` `

Vitim.us

Posted 2016-03-22T17:45:18.033

Reputation: 181

1Unfortunately, this is a snippet (s isn't ever defined), but to make it a valid submission you can add s=> to the start. – caird coinheringaahing – 2017-12-14T16:07:43.160

1

Brain-Flak, 46 bytes

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

Try it online!

Explanation:

#Reverse the whole stack
{({}<>)<>}<>

#Reverse the whole stack, 
{({}<>)

    #Pushing 32 between each character
    ((((()()()()){}){}){})<>}<>

James

Posted 2016-03-22T17:45:18.033

Reputation: 54 537

1

APL (Dyalog), 4 bytes

Requires ⎕ML←0 which used to be standard

,⍪,∊

Try it online!

, ravel (flatten)

 the columnified argument

, followed by

 the prototypes (one space per character)

Adám

Posted 2016-03-22T17:45:18.033

Reputation: 37 779

Can you explain why this needs to be encoded in UTF-8? – Zacharý – 2017-07-26T16:01:22.633

@Zacharý Does it? Is ⎕AVU no good? – Adám – 2017-07-26T16:03:31.830

Clarification: Why this is 12 bytes and not 4? – Zacharý – 2017-07-26T16:06:15.150

@Zacharý Ah, simple mistake. – Adám – 2017-07-26T16:30:04.027

1

Julia, 31 bytes

print(join(readline(),' ')*" ")

Try it online!

LukeS

Posted 2016-03-22T17:45:18.033

Reputation: 421

1Welcome to PPCG! – Rɪᴋᴇʀ – 2017-12-17T17:43:57.720

1

Python 3, 95 93 92 80 32 26 30 bytes

Saved a byte thanks to @caird coinheringaahing

Saved bunch of bytes from @DJMcMayhem + My idea

print(' '.join(input())+' ')

Takes input, splits it, then prints a join with spaces

This is my first time golfing.

Mercury Platinum

Posted 2016-03-22T17:45:18.033

Reputation: 161

1

Welcome to the site! You can remove a byte by removing the space after the : as well as taking a look at these tips for Python golfing

– caird coinheringaahing – 2018-01-26T16:26:51.010

You could get this down to a one-liner: print(''.join(i+' 'for i in input()) – James – 2018-01-26T16:41:19.740

1@DJMcMayhem, made it even shorter :) – Mercury Platinum – 2018-01-26T16:45:15.857

Does this print a space after the last character? And do you need the list() part? – Jo King – 2018-01-27T05:36:43.263

oh, one second. – Mercury Platinum – 2018-01-27T16:36:51.330

1

Brainfuck, 23 24 25 Bytes

1 Byte thanks to ovs

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

Try it online!
This code makes use of most interpreters wrapping to 255 if the number is negative.

Previous solution:

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

Try it online!

Explanation:

++++[>++++++++<-]   |Leaves the second cell with the number 32, the ASCII Code for a space.
+[,.>.<]            |Simple loop, gets the input, outputs it and adds a space.

Suggestions are welcome.

Dust

Posted 2016-03-22T17:45:18.033

Reputation: 131

24 bytes. The initialization part is taken from this page – ovs – 2018-01-27T10:13:00.647

Cool, very nice. I have problems understanding your program though. Could you explain it to me? – Dust – 2018-01-27T10:21:55.957

The code makes use of the fact that most brainfuck implementations use wrapping 8-bit cells. If you decrement a cell that is zero, you get to 255. Here is a simple example.

– ovs – 2018-01-27T10:35:10.557

The , should be at the end of the loop, otherwise you print an extra nul byte. Try it online!

– Jo King – 2019-02-12T00:47:32.107

1

Canvas, 4 3 bytes

 ]∑

Try it here!

Explanation:
   Push input to stack (implicit)
   For each character in the input: (implicit)
   Push the character to the stack (implicit)
   Push " " to the stack
] Collapse results from loop into an array
∑  Join the array into a single string
   Print the ToS (implicit)

-1 byte thanks to dzaima!

hakr14

Posted 2016-03-22T17:45:18.033

Reputation: 1 295

1You can remove the leading as it can be implicit for 3 bytes – dzaima – 2018-03-06T16:23:22.070

1

k, 10 bytes

{,/x,'" "}

Explanation

{..} is the lambda syntax

x,'"" takes the first argument x, and applies the join operator , to every character, creating an array of "l " pairs

,/ folds the array with the join operator

ulucs

Posted 2016-03-22T17:45:18.033

Reputation: 91

1

Gol><>, 7 bytes

iEH}` }

Courtesy of JoKing, who golfed this to the max!!! JoKing combined the loops into one simple loop, also avoided the mistake I made, I added 2 spaces rather than one.

Try it online!

Slightly newer of My original golfed, 23 bytes

Ti:0)?t~l&T` }}&M:&?trH

Try it online!

Old version, 28 bytes

Ti:0)?t~l&T"  "}}}&M:&0)?trH

This can probably be golfed futher, but code breakdown below!

Ti:0)?t~l&T"  "}}}&M:&0)?trH

Ti:0)?t~                    //gets every char from input, and pushes them to the stack
          T"  "}}}          //push 2 spaces after every char, push to the bottom of the stack for later
        l&T       &M:&0)?t  //push original length and store, every loop decrement and if it is greater than zero, repeat
                          rH//reverse stack and output the whole stack as characters

Try it online!

KrystosTheOverlord

Posted 2016-03-22T17:45:18.033

Reputation: 681

7 bytes. Mostly because you can combine all the loops into one loop over the input – Jo King – 2019-02-12T00:29:30.267

@JoKing Wow, that is really smart using the E function! Also I just realized that it only needs one space, and that I forgot to add spaces after the last characters, sorry! – KrystosTheOverlord – 2019-02-12T00:31:35.930

@JoKing Almost managed 6 bytes, but it prints entirely backwards... iEH@` – KrystosTheOverlord – 2019-02-12T00:44:26.063

1

PowerShell, 24 bytes

"$args"-replace'.','$0 '

Try it online!

mazzy

Posted 2016-03-22T17:45:18.033

Reputation: 4 832

1

APL(NARS), 13 chars, 26 bytes

∊k,¨' '⍴⍨≢k←⍞

Input a line from standard input, and return a line, test:

∊k,¨' '⍴⍨≢k←⍞
hello there
h e l l o   t h e r e 

RosLuP

Posted 2016-03-22T17:45:18.033

Reputation: 3 036

1

Zsh, 21 bytes

echo ${(s::)$(<&0)}\ 

Try it online!

$(capture), ${(s::)plit}, echo. The last "\ " is needed for the trailing space.

GammaFunction

Posted 2016-03-22T17:45:18.033

Reputation: 2 838

1

Befunge-98 (PyFunge), 6 bytes

"#@~,,

Try it online!

The Befunge-98 answer is pretty long, so here is a shorter one. Basically the same answer as this Befunge-93 answer by Sp3000, but ends up being half as long, thanks to Befunge-98s ~ reflecting on EOF.

One thing that bugged me is, that when you run it on multi line input, every line but the first will be indented (since the linebreak will be followed by a space as well), so here is a version (11 bytes), that doesn't have that problem.

"#@~:,a-!j,

Try it online!

david

Posted 2016-03-22T17:45:18.033

Reputation: 180

1

W, 4 bytes

 "+M

Explanation

   M % Foreach the input list:
  +  % Join the current item with ...
 "   % ... A space character

user85052

Posted 2016-03-22T17:45:18.033

Reputation:

1

Keg, -rs, 3 bytes

( '

Shifts the input putting a space after each character, reverses the stack via the -rs flag and then implicitly outputs the stack.

Lyxal

Posted 2016-03-22T17:45:18.033

Reputation: 5 253

1

PowerShell, 17 8 bytes

-9 bytes thanks to @mazzy!

"$args "

Try it online!

There are already a couple of PowerShell answers to this question, but I thought I'd throw mine into the mix. It takes splatter input from a command line argument. It also assumes that $ofs is equal to one space, which it is by default.

Gabriel Mills

Posted 2016-03-22T17:45:18.033

Reputation: 778

1

Great! The codegolf allow you to use an char array instead of a string. Therefore, 8 bytes

– mazzy – 2020-01-02T07:21:52.943

@mazzy finally, a competitive PowerShell answer ;) thanks! – Gabriel Mills – 2020-01-02T16:37:31.610

1

Minkolang 0.15 - 9 bytes

od?.O" "O

Try it here!

Explanation

o            Take character from input
 d           Duplicate top of stack
  ?.         Pop top of stack and jump over the . if truthy, stop otherwise
    O        Output input char
     " "O    Output a space

Minkolang's codebox is toroidal, hence there is no need to put an explicit loop in it.

El'endia Starman

Posted 2016-03-22T17:45:18.033

Reputation: 14 504

1

Convex, 3 bytes

Convex is a new language that I am developing that is heavily based on CJam and Golfscript. The interpreter and IDE can be found here. Input is an integer into the command line arguments. Indexes are one-based. Uses the CP-1252 encoding.

S*S

Explanation:

     # Implied input
S*   # Join by spaces
  S  # Add a space at the end
     # Implied output

Additionally, @DonMuesli's CJam answer without the l (so Sf+) will also work for 3 bytes.

GamrCorps

Posted 2016-03-22T17:45:18.033

Reputation: 7 058

Update this post later? – CalculatorFeline – 2016-03-23T02:25:09.710

@CatsAreFluffy oh, my bad, I forgot, will do now. – GamrCorps – 2016-03-23T02:38:27.447

1

sed, 8 bytes

s/./& /g

When running this from the shell you should quote it of course e.g.

echo Full Width Text | sed 's/./& /g' | od -c

Neil

Posted 2016-03-22T17:45:18.033

Reputation: 95 035

1

Python 3, 39 bytes

print("".join([x+" "for x in input()]))

Yytsi

Posted 2016-03-22T17:45:18.033

Reputation: 3 582

1You could just join with a " " rather than insert it with the comprehension. Then all you need to worry about is the trailing space at the end. print(" ".join(input())+" ") gets you down to 28 bytes – wnnmaw – 2016-03-23T16:15:58.097

This is now exact duplicate of Raffi's answer, which reached this format 1 day 01:30:09 hour earlier.

– manatwork – 2016-03-24T10:34:22.787

@manatwork I see. Should I change my old answer back or something? Thanks for telling! – Yytsi – 2016-03-24T11:37:16.343

1Just improve it more. ;) In meantime I would revert to the previous version – it demonstrates the usage of a very popular Python feature, which has better chances for positive votes than a duplicate. – manatwork – 2016-03-24T12:17:44.383

@manatwork Very good point! Reverted it. Back to 39 bytes :D – Yytsi – 2016-03-24T12:32:03.777

1

Ruby, 41 bytes

puts gets.chomp.chars.map{|e|e+" "}.join

chomp eats trailing newlines.

jose_castro_arnaud

Posted 2016-03-22T17:45:18.033

Reputation: 229

1There is no requirement to output the whole result at once. If you output it piece-by-piece, you can spare the .join call. Even more, if you not need to return the pieces from the code block, then you can spare the .map call too, as .chars also accepts code block. And there is no restriction against adding a space after the trailing newline too, if there is one. gets.chars{|e|$><<e+" "} – manatwork – 2016-03-23T10:47:51.123

1

SMBF, 9 bytes

Note the trailing space. Uses the space in the code rather than creating a 32 in a cell.

,[.<.>,] 

The tryitonline.net interpreter appears to have a bug and loop indefinitely with this, so it only works in my Python interpreter. Changing the SMBF source code (currently on line 171) inside the Python code is required.

mbomb007

Posted 2016-03-22T17:45:18.033

Reputation: 21 944

1

Go, 154 120 bytes

package main
import(
."fmt"
."os"
."strings")
func main(){s:=Join(Args[1:], " ")
for _,c:=range s{Print(string(c)," ")}}

Saved a few bytes with command line args.

EMBLEM

Posted 2016-03-22T17:45:18.033

Reputation: 2 179

1

Vitsy, 10 bytes

zl\[O' 'O]

z          Grab all string input.
 l\[     ] Do the stuff in the brackets length of the stack times.
    O   O  Output as character.
     ' '   Push literal space.

Try it online!

Addison Crump

Posted 2016-03-22T17:45:18.033

Reputation: 10 763

1

Scala, 35 bytes

Console.readLine.map(_+" ")mkString

Example:

scala> Console.readLine.map(_+" ")mkString
res1: String = "H e l l o   S c a l a ! "

PS. A function would be slightly shorter (32 bytes):

(s:String)=>s.map(_+" ")mkString

lambruscoAcido

Posted 2016-03-22T17:45:18.033

Reputation: 401

1

LiveScript, 17.

->"#{it/''*' '} "

Ven

Posted 2016-03-22T17:45:18.033

Reputation: 3 382

1

APL, 11 bytes

{,/' ',¨⍵}

catenate ' ' with each in omega (argument), then join (reduce-catenate, ,/)

Ven

Posted 2016-03-22T17:45:18.033

Reputation: 3 382

You don't need the anymore. 10 bytes: {,/⍵,¨' '} – Zacharý – 2017-07-26T17:28:30.777

@Zacharý "anymore"? – Ven – 2017-07-26T18:24:37.990

I thought you originally had it to save bytes, guess I was wrong. Either way, you don't need . – Zacharý – 2017-07-26T18:29:54.027

1

Mathematica, 42 bytes

Print@@(#<>" "&)/@Characters@InputString[]

Pretty self-explanatory. InputString takes a line from STDIN, Characters converts it to a list of characters, (#<>" "&)/@ produces a new string with spaces after those characters, and Print prints the result.

LegionMammal978

Posted 2016-03-22T17:45:18.033

Reputation: 15 731

1

Perl 5, 11 10 + 1 flags = 11 bytes

really, the same as the Perl 6 one, but the sed syntax changed.

s/./$& /g

example:

perl -pe "s/./$& /g" <<< abc

old:

perl -pne "s/(.)/\1 /g" <<< abc

Ven

Posted 2016-03-22T17:45:18.033

Reputation: 3 382

Can you save a byte by using s/./$& /gp? – Neil – 2016-03-22T22:01:34.620

1The -n flag is unnecessary, isn't it? – Doorknob – 2016-03-22T22:40:25.977

@Doorknob is indeed correct, you can omit -p, also, how flexible is the output format? If a leading space is acceptable s// /g works too! – Dom Hastings – 2016-03-23T08:47:45.990

I don't think I'm allowed to have a leading space :). Thanks @Doorknob – Ven – 2016-03-23T09:15:08.057

1

Batch, 87 bytes

@set/pt=&set w=
:l
@if not "%t%"=="" set w=%w%%t:~,1% &set t=%t:~1%&goto l
@echo(%w%

Conveniently taking input from STDIN is the same length as taking it from program arguments (set t=%*). The space between the % and & on the third line is significant, of course. The ( after the echo simply prevents it from erroring out if the input is empty.

Neil

Posted 2016-03-22T17:45:18.033

Reputation: 95 035

1

Python 3, 31 28

print(' '.join(input())+' ')

I know i'm late on this one, and definitely not a winner, but thought i'd try it out.

Edit: Switched to python 3. Thanks to CatsAreFluffy for saving 3 bytes!

Raffi

Posted 2016-03-22T17:45:18.033

Reputation: 137

You can cut one byte by removing the space after print. – Zach Gates – 2016-03-22T22:53:06.873

Or just switch to Python 3 (and cut 3 bytes): print(' '.join(input)+' '). raw_input is more expensive than parens with print. – CalculatorFeline – 2016-03-23T02:31:26.467

1

Grond, 22 21 chars

a(p().sp('').jn(' '))

Edit: removed semicolon
compiler in js below

String.prototype.reverse = function() {
  return this.split("").reverse().join("");
}
function compile(source){
var wc = source; // wc stands for working copy 
var lastWC;
while (true) {
  lastWC = wc;
  wc = wc.reverse();
  wc = wc.replace(/\(a(?!\w)/, "(trela"); //alert ,a
  wc = wc.replace(/\(f(?!\w)/, "(rof"); // for, f
  wc = wc.replace(/\(w(?!\w)/, "(elihw"); //while,w
  wc = wc.replace(/\(p(?!\w)/, "(tpmorp"); //prompt,p
  wc = wc.replace(/\(vr\./, "(esrever."); //reverse, rv
  wc = wc.replace(/\(tm\./, "(chtam."); // match, mt
  wc = wc.replace(/\(nj\./, "(nioj."); //join, .jn
  wc = wc.replace(/\(pr\./, "(ecalper."); //replace, .rp
  wc = wc.replace(/\(ls\./, "(.ecils"); //slice, sl
  wc = wc.replace(/\(lt\./, "(esaCrewoLot."); //toLowerCase, tl
  wc = wc.replace(/\(ut\./, "(esaCreppUot."); //toUpperCase, tu
    wc = wc.replace(/\(ps\./, "(tilps."); //split, sp
  wc = wc.reverse();
  wc = wc.replace(/\.l(?!\w)/, ".length"); // .length, .l
  if (lastWC === wc)
    break;
}

// quine builtin commented out because it messes things up TODO: Fix it. 
wc = " String.prototype.la=function(h){var x=this.split(''); x[h] = x[h].toLowerCase(); return x.join('');};String.prototype.ca=function(h){var x=this.split(''); x[h] = x[h].toUpperCase(); return x.join('');};String.prototype.reverse=function(){return this.split('').reverse().join('');}; \n var h = ['hello, world', 'Hello, World', 'Hello, World!', 'hello, world!', 'hello world', 'hello world!', 'Hello World', 'Hello World!', 'Hello, world.', 'Hello, World.' ,'hello world.' , 'Hello World.']; /* var q ='" + source + "';*/ " + wc;

return wc;
  }
eval(compile("a(p().sp('').jn(' '));"));//source
Grond on github: https://github.com/epicTCK/Grond

Bald Bantha

Posted 2016-03-22T17:45:18.033

Reputation: 463

1

C, 48 bytes

main(c){for(c=8192;read(0,&c,1);write(1,&c,2));}

Try it online

xsot

Posted 2016-03-22T17:45:18.033

Reputation: 5 069

1

Nim, 41 bytes

for c in stdin.readAll:stdout.write c&' '

I sure hope there's a better way, but readChar didn't seem to help...

Ideone link

Sp3000

Posted 2016-03-22T17:45:18.033

Reputation: 58 729

1

Reng v.1.2, 15 bytes

Try it out here! The input is given as "input".

ai p|$raoWo?!|~

a is a one-way mirror from the left. ai p| gets all input, $ drops the residual -1 not found input, r reverses the stack, and aoWo?!|~ is an output loop. W pushes 32, the space, and outputs it after outputting the character. ?! breaks out if not true, and ~ ends the program.

Conor O'Brien

Posted 2016-03-22T17:45:18.033

Reputation: 36 228

1

RETURN, 10 bytes

`""¨{' °},

Try it here.

Takes input from STDIN. It's just take STDIN, split along chars, join with space, output.

Mama Fun Roll

Posted 2016-03-22T17:45:18.033

Reputation: 7 234

1

Jolf, 7 bytes

Try it here!

p4i*li♣
p4       interweave
  i      the input
   *li♣  with a string of spaces with = length to the input

Conor O'Brien

Posted 2016-03-22T17:45:18.033

Reputation: 36 228

1

, 5 chars / 7 bytes

ᴉü⬭+⬭

Try it here (Firefox only).

Short and sweet. Get input split along chars and join with space.

Mama Fun Roll

Posted 2016-03-22T17:45:18.033

Reputation: 7 234

This doesn't produce a trailing space. – Conor O'Brien – 2016-03-23T15:48:04.133

I think I fixed it, but I'm on my phone. – Mama Fun Roll – 2016-03-23T16:12:49.527

1

Clojure, 34 bytes

#(apply str(mapcat(fn[x][x" "])%))

Clojure is amazingly fun to work with but annoying to golf. Usually there's a really nice idiomatic solution to these challenges that isn't that many identifiers, but it's massive thanks to things like the identity function being identity (not fully golfed in these forms):

(defn fw [s] (apply str (interleave s (repeat " "))))

or

(defn fw [s] (apply str (mapcat (juxt identity (constantly " ")) s)))

MattPutnam

Posted 2016-03-22T17:45:18.033

Reputation: 521

1

Lua, 31 Bytes

Saved 1 byte thanks to @LeakyNun

A simple chained substitution, replace each character by itself and a space.

s=(...):gsub(".","%1 ")print(s)

An other solution with the same byte count:

print((...):gsub(".","%1 "),'')

Katenkyo

Posted 2016-03-22T17:45:18.033

Reputation: 2 857

@manatwork I don't see how I did to miss this! Print automatically had a tab between each of it's parameters, totally forgot that point. Thanks for the comment! – Katenkyo – 2016-04-04T07:41:26.107

Can you change arg[1] to ...? – Leaky Nun – 2016-07-01T07:57:08.473

1

O 1.2, 6 bytes

I' ]^o

Sample run:

bash-4.3$ java xyz.jadonfowler.o.O <(echo "I' ]^o") <<< 'Full width text.'
F u l l   w i d t h   t e x t . 

This could be 5 characters in O 2 as IT]^o, but sadly it not seems to fully support the ^ command yet.

manatwork

Posted 2016-03-22T17:45:18.033

Reputation: 17 865

1

J, 8 bytes

,@,.&' '

,. is the stitch command, and ' ' , 'string' creates a table with a space following each character. , takes these items out of the table when used as a monad, and @ composes this function with our other function. Use:

   fullWidth =: ,@,.&' '
   fullWidth 'this text is full width!'
   fullWidth 'this text is full width!'
t h i s   t e x t   i s   f u l l   w i d t h ! 

Great thanks to Zgarb who helped me make this answer.

Conor O'Brien

Posted 2016-03-22T17:45:18.033

Reputation: 36 228

1

PowerShell, 32 bytes

-join([char[]]$args[0]|%{"$_ "})

Explanation

Take in the input to the function and convert it to a char array. Add one space to each character and rejoin. Nothing really fancy here.

Matt

Posted 2016-03-22T17:45:18.033

Reputation: 1 075

Save a couple bytes by just joining it directly and encapsulating in a script block in a string -- "$([char[]]$args[0]-join' ') " – AdmBorkBork – 2016-07-26T16:02:15.180

1

Prelude, 11 bytes

?(!8^+^+!?)

This needs a spec-compliant interpreter which reads and writes character codes (instead of integers).

The program is fairly simple.

?(...?)

This sets up a while(read() != EOF) loop. Then we simply have:

!   Print input character.
8   Push 8.
^+  Duplicate, add. Gives 16.
^+  Duplicate, add. Gives 32.
!   Print space.

Martin Ender

Posted 2016-03-22T17:45:18.033

Reputation: 184 808

1

Common Lisp, 40 bytes

(map()(lambda(x)(format t"~C "x))(read))

I was very surprised that format couldn't do this by itself: it can only iterate over lists, not strings.

Soupy

Posted 2016-03-22T17:45:18.033

Reputation: 151

1

Pip, 5 bytes

_.sMq

The special variable q reads a line of stdin. We Map to it the lambda function _.s, which concatenates a space to each character. By default, the resulting list is concatenated and autoprinted.

DLosc

Posted 2016-03-22T17:45:18.033

Reputation: 21 213

1

Ouroboros, 11 bytes

i.0<5*(o32o

Ouroboros is an esolang in which every line of code represents a snake eating its tail. It draws a fair amount of inspiration from 2D languages like Befunge and ><>.

The i command reads a character, or -1 for EOF. We duplicate this, check if it's less than 0, and multiply the resulting 1 (true) or 0 (false) by 5.

  • If we have reached EOF, the top of the stack is now 5. The ( command tells the snake to eat that many characters of its tail. This results in swallowing the execution pointer (currently on (, the fifth-last character), which terminates the program.
  • Otherwise, 0 characters are eaten, and execution continues. We have a copy of the input ASCII code on the stack, which we output via o; then output a space (ASCII 32) and loop back to the beginning.

Try it out

// Define Stack class
function Stack() {
  this.stack = [];
  this.length = 0;
}
Stack.prototype.push = function(item) {
  this.stack.push(item);
  this.length++;
}
Stack.prototype.pop = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack.pop();
    this.length--;
  }
  return result;
}
Stack.prototype.top = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack[this.length - 1];
  }
  return result;
}
Stack.prototype.toString = function() {
  return "" + this.stack;
}

// Define Snake class
function Snake(code) {
  this.code = code;
  this.length = this.code.length;
  this.ip = 0;
  this.ownStack = new Stack();
  this.currStack = this.ownStack;
  this.alive = true;
  this.wait = 0;
  this.partialString = this.partialNumber = null;
}
Snake.prototype.step = function() {
  if (!this.alive) {
    return null;
  }
  if (this.wait > 0) {
    this.wait--;
    return null;
  }
  var instruction = this.code.charAt(this.ip);
  var output = null;
  console.log("Executing instruction " + instruction);
  if (this.partialString !== null) {
    // We're in the middle of a double-quoted string
    if (instruction == '"') {
      // Close the string and push its character codes in reverse order
      for (var i = this.partialString.length - 1; i >= 0; i--) {
        this.currStack.push(this.partialString.charCodeAt(i));
      }
      this.partialString = null;
    } else {
      this.partialString += instruction;
    }
  } else if (instruction == '"') {
    this.partialString = "";
  } else if ("0" <= instruction && instruction <= "9") {
    if (this.partialNumber !== null) {
      this.partialNumber = this.partialNumber + instruction;  // NB: concatenation!
    } else {
      this.partialNumber = instruction;
    }
    next = this.code.charAt((this.ip + 1) % this.length);
    if (next < "0" || "9" < next) {
      // Next instruction is non-numeric, so end number and push it
      this.currStack.push(+this.partialNumber);
      this.partialNumber = null;
    }
  } else if ("a" <= instruction && instruction <= "f") {
    // a-f push numbers 10 through 15
    var value = instruction.charCodeAt(0) - 87;
    this.currStack.push(value);
  } else if (instruction == "$") {
    // Toggle the current stack
    if (this.currStack === this.ownStack) {
      this.currStack = this.program.sharedStack;
    } else {
      this.currStack = this.ownStack;
    }
  } else if (instruction == "s") {
    this.currStack = this.ownStack;
  } else if (instruction == "S") {
    this.currStack = this.program.sharedStack;
  } else if (instruction == "l") {
    this.currStack.push(this.ownStack.length);
  } else if (instruction == "L") {
    this.currStack.push(this.program.sharedStack.length);
  } else if (instruction == ".") {
    var item = this.currStack.pop();
    this.currStack.push(item);
    this.currStack.push(item);
  } else if (instruction == "m") {
    var item = this.ownStack.pop();
    this.program.sharedStack.push(item);
  } else if (instruction == "M") {
    var item = this.program.sharedStack.pop();
    this.ownStack.push(item);
  } else if (instruction == "y") {
    var item = this.ownStack.top();
    this.program.sharedStack.push(item);
  } else if (instruction == "Y") {
    var item = this.program.sharedStack.top();
    this.ownStack.push(item);
  } else if (instruction == "\\") {
    var top = this.currStack.pop();
    var next = this.currStack.pop()
    this.currStack.push(top);
    this.currStack.push(next);
  } else if (instruction == "@") {
    var c = this.currStack.pop();
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(c);
    this.currStack.push(a);
    this.currStack.push(b);
  } else if (instruction == ";") {
    this.currStack.pop();
  } else if (instruction == "+") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a + b);
  } else if (instruction == "-") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a - b);
  } else if (instruction == "*") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a * b);
  } else if (instruction == "/") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a / b);
  } else if (instruction == "%") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a % b);
  } else if (instruction == "_") {
    this.currStack.push(-this.currStack.pop());
  } else if (instruction == "I") {
    var value = this.currStack.pop();
    if (value < 0) {
      this.currStack.push(Math.ceil(value));
    } else {
      this.currStack.push(Math.floor(value));
    }
  } else if (instruction == ">") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a > b));
  } else if (instruction == "<") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a < b));
  } else if (instruction == "=") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a == b));
  } else if (instruction == "!") {
    this.currStack.push(+ !this.currStack.pop());
  } else if (instruction == "?") {
    this.currStack.push(Math.random());
  } else if (instruction == "n") {
    output = "" + this.currStack.pop();
  } else if (instruction == "o") {
    output = String.fromCharCode(this.currStack.pop());
  } else if (instruction == "r") {
    var input = this.program.io.getNumber();
    this.currStack.push(input);
  } else if (instruction == "i") {
    var input = this.program.io.getChar();
    this.currStack.push(input);
  } else if (instruction == "(") {
    this.length -= Math.floor(this.currStack.pop());
    this.length = Math.max(this.length, 0);
  } else if (instruction == ")") {
    this.length += Math.floor(this.currStack.pop());
    this.length = Math.min(this.length, this.code.length);
  } else if (instruction == "w") {
    this.wait = this.currStack.pop();
  }
  // Any unrecognized character is a no-op
  if (this.ip >= this.length) {
    // We've swallowed the IP, so this snake dies
    this.alive = false;
    this.program.snakesLiving--;
  } else {
    // Increment IP and loop if appropriate
    this.ip = (this.ip + 1) % this.length;
  }
  return output;
}
Snake.prototype.getHighlightedCode = function() {
  var result = "";
  for (var i = 0; i < this.code.length; i++) {
    if (i == this.length) {
      result += '<span class="swallowedCode">';
    }
    if (i == this.ip) {
      if (this.wait > 0) {
        result += '<span class="nextActiveToken">';
      } else {
        result += '<span class="activeToken">';
      }
      result += escapeEntities(this.code.charAt(i)) + '</span>';
    } else {
      result += escapeEntities(this.code.charAt(i));
    }
  }
  if (this.length < this.code.length) {
    result += '</span>';
  }
  return result;
}

// Define Program class
function Program(source, speed, io) {
  this.sharedStack = new Stack();
  this.snakes = source.split(/\r?\n/).map(function(snakeCode) {
    var snake = new Snake(snakeCode);
    snake.program = this;
    snake.sharedStack = this.sharedStack;
    return snake;
  }.bind(this));
  this.snakesLiving = this.snakes.length;
  this.io = io;
  this.speed = speed || 10;
  this.halting = false;
}
Program.prototype.run = function() {
  this.step();
  if (this.snakesLiving) {
    this.timeout = window.setTimeout(this.run.bind(this), 1000 / this.speed);
  }
}
Program.prototype.step = function() {
   for (var s = 0; s < this.snakes.length; s++) {
    var output = this.snakes[s].step();
    if (output) {
      this.io.print(output);
    }
  }
  this.io.displaySource(this.snakes.map(function (snake) {
      return snake.getHighlightedCode();
    }).join("<br>"));
 }
Program.prototype.halt = function() {
  window.clearTimeout(this.timeout);
}

var ioFunctions = {
  print: function (item) {
    var stdout = document.getElementById('stdout');
    stdout.value += "" + item;
  },
  getChar: function () {
    if (inputData) {
      var inputChar = inputData[0];
      inputData = inputData.slice(1);
      result = inputChar.charCodeAt(0);
    } else {
      result = -1;
    }
    var stdinDisplay = document.getElementById('stdin-display');
    stdinDisplay.innerHTML = escapeEntities(inputData);
    return result;
  },
  getNumber: function () {
    while (inputData && (inputData[0] < "0" || "9" < inputData[0])) {
      inputData = inputData.slice(1);
    }
    if (inputData) {
      var inputNumber = inputData.match(/\d+/)[0];
      inputData = inputData.slice(inputNumber.length);
      result = +inputNumber;
    } else {
      result = -1;
    }
    var stdinDisplay = document.getElementById('stdin-display');
    stdinDisplay.innerHTML = escapeEntities(inputData);
    return result;
  },
  displaySource: function (formattedCode) {
    var sourceDisplay = document.getElementById('source-display');
    sourceDisplay.innerHTML = formattedCode;
  }
};
var program = null;
var inputData = null;
function showEditor() {
  var source = document.getElementById('source'),
    sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
    stdin = document.getElementById('stdin'),
    stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
  
  source.style.display = "block";
  stdin.style.display = "block";
  sourceDisplayWrapper.style.display = "none";
  stdinDisplayWrapper.style.display = "none";
  
  source.focus();
}
function hideEditor() {
  var source = document.getElementById('source'),
    sourceDisplay = document.getElementById('source-display'),
    sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
    stdin = document.getElementById('stdin'),
    stdinDisplay = document.getElementById('stdin-display'),
    stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
  
  source.style.display = "none";
  stdin.style.display = "none";
  sourceDisplayWrapper.style.display = "block";
  stdinDisplayWrapper.style.display = "block";
  
  var sourceHeight = getComputedStyle(source).height,
    stdinHeight = getComputedStyle(stdin).height;
  sourceDisplayWrapper.style.minHeight = sourceHeight;
  sourceDisplayWrapper.style.maxHeight = sourceHeight;
  stdinDisplayWrapper.style.minHeight = stdinHeight;
  stdinDisplayWrapper.style.maxHeight = stdinHeight;
  sourceDisplay.textContent = source.value;
  stdinDisplay.textContent = stdin.value;
}
function escapeEntities(input) {
  return input.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
function resetProgram() {
  var stdout = document.getElementById('stdout');
  stdout.value = null;
  if (program !== null) {
    program.halt();
  }
  program = null;
  inputData = null;
  showEditor();
}
function initProgram() {
  var source = document.getElementById('source'),
    stepsPerSecond = document.getElementById('steps-per-second'),
    stdin = document.getElementById('stdin');
  program = new Program(source.value, +stepsPerSecond.innerHTML, ioFunctions);
  hideEditor();
  inputData = stdin.value;
}
function runBtnClick() {
  if (program === null || program.snakesLiving == 0) {
    resetProgram();
    initProgram();
  } else {
    program.halt();
    var stepsPerSecond = document.getElementById('steps-per-second');
    program.speed = +stepsPerSecond.innerHTML;
  }
  program.run();
}
function stepBtnClick() {
  if (program === null) {
    initProgram();
  } else {
    program.halt();
  }
  program.step();
}
function sourceDisplayClick() {
  resetProgram();
}
.container {
    width: 100%;
}
.so-box {
    font-family:'Helvetica Neue', Arial, sans-serif;
    font-weight: bold;
    color: #fff;
    text-align: center;
    padding: .3em .7em;
    font-size: 1em;
    line-height: 1.1;
    border: 1px solid #c47b07;
    -webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
    background: #f88912;
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
}
.control {
    display: inline-block;
    border-radius: 6px;
    float: left;
    margin-right: 25px;
    cursor: pointer;
}
.option {
    padding: 10px 20px;
    margin-right: 25px;
    float: left;
}
h1 {
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
}
a {
    text-decoration: none;
}
input, textarea {
    box-sizing: border-box;
}
textarea {
    display: block;
    white-space: pre;
    overflow: auto;
    height: 50px;
    width: 100%;
    max-width: 100%;
    min-height: 25px;
}
span[contenteditable] {
    padding: 2px 6px;
    background: #cc7801;
    color: #fff;
}
#stdout-container, #stdin-container {
    height: auto;
    padding: 6px 0;
}
#reset {
    float: right;
}
#source-display-wrapper , #stdin-display-wrapper{
    display: none;
    width: 100%;
    height: 100%;
    overflow: auto;
    border: 1px solid black;
    box-sizing: border-box;
}
#source-display , #stdin-display{
    font-family: monospace;
    white-space: pre;
    padding: 2px;
}
.activeToken {
    background: #f93;
}
.nextActiveToken {
    background: #bbb;
}
.swallowedCode{
    color: #999;
}
.clearfix:after {
    content:".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
.clearfix {
    display: inline-block;
}
* html .clearfix {
    height: 1%;
}
.clearfix {
    display: block;
}
<!--
Designed and written 2015 by D. Loscutoff
Much of the HTML and CSS was taken from this Befunge interpreter by Ingo Bürk: http://codegolf.stackexchange.com/a/40331/16766
-->
<div class="container">
<textarea id="source" placeholder="Enter your program here" wrap="off">i.0<5*(o32o</textarea>
<div id="source-display-wrapper" onclick="sourceDisplayClick()"><div id="source-display"></div></div></div><div id="stdin-container" class="container">
<textarea id="stdin" placeholder="Input" wrap="off">Input text...</textarea>
<div id="stdin-display-wrapper" onclick="stdinDisplayClick()"><div id="stdin-display"></div></div></div><div id="controls-container" class="container clearfix"><input type="button" id="run" class="control so-box" value="Run" onclick="runBtnClick()" /><input type="button" id="pause" class="control so-box" value="Pause" onclick="program.halt()" /><input type="button" id="step" class="control so-box" value="Step" onclick="stepBtnClick()" /><input type="button" id="reset" class="control so-box" value="Reset" onclick="resetProgram()" /></div><div id="stdout-container" class="container"><textarea id="stdout" placeholder="Output" wrap="off" readonly></textarea></div><div id="options-container" class="container"><div class="option so-box">Steps per Second:
<span id="steps-per-second" contenteditable>20</span></div></div>

DLosc

Posted 2016-03-22T17:45:18.033

Reputation: 21 213

1

Pyth, 5 bytes

+jdzd

Test here

Explanation:

 jdz    Join input with spaces
+   d   Concatenate space

Arfie

Posted 2016-03-22T17:45:18.033

Reputation: 1 230

1

Silicon, 7 bytes

Note that this is non-competing. How I wish that I would have made Silicon last year...

iSæ²jæ+

Explanation:

i        Input
S        Split the input
æ        Push a space
²j       Join at spaces
æ+       Append a space to the end of the string
         Implicit output

m654

Posted 2016-03-22T17:45:18.033

Reputation: 765

1Does Silicon have it's own encoding? Else, it would be 10 bytes in UTF-8 (and 7 chars). – Katenkyo – 2016-07-06T09:07:00.520

1

0815, 26 bytes

<:20:~>}: :!~$#:
:{~$>^: :

Erik the Outgolfer

Posted 2016-03-22T17:45:18.033

Reputation: 38 134

1

Tcl, 44 bytes

puts [regsub -all {(.)} [gets stdin] {\1 }]

Byeonggon Lee

Posted 2016-03-22T17:45:18.033

Reputation: 419

You're byte count is wrong! It is 43! – sergiol – 2017-01-12T03:22:43.490

1

C#, 35 bytes

s=>string.Join(" ",s.ToList())+" ";

C# lambda where the input and the output are string. You can try it on .NetFiddle.

aloisdg moving to codidact.com

Posted 2016-03-22T17:45:18.033

Reputation: 1 767

This requires a using System.Linq derivative, which should either be included or the language marked as LinqPad or similar. – VisualMelon – 2017-01-12T11:07:07.937

1

Swift 2.2, 48 46 bytes

for c in i.characters{print(c,terminator:" ")}

Hey, at least it's shorter than Java... Saved 2 chars by using a for in loop instead of a forEach closure.

JAL

Posted 2016-03-22T17:45:18.033

Reputation: 304

0

Excel VBA, 21 19 Bytes

Anonymous VBE immediate window function that takes input from cell [A1] and outputs to the VBE immediate window

?StrConv([A1],64)" 

-1 Byte for removing & in ? statement

-1 Byte for removing terminal " from " "

Taylor Scott

Posted 2016-03-22T17:45:18.033

Reputation: 6 709

0

MY, 8 bytes (noncompeting)

⍞ηυ←2Ġ'←

Try it online!

Explanation:

  • 1E/⍞ - receive a line of input from STDIN
  • 57/η - split into individual characters
  • 58/υ - joined by spaces
  • 26/← - print to STDOUT without a newline
  • 02/2 - push 2 to the stack
  • 25/Ġ - hexadecimal shift (pop n; push 16n. 2 * 16 is 32, which is the ASCII codepoint of the space)
  • 28/' - convert to character (The space character, υ doesn't add a space to the end of the string)
  • 26/← - output with no newline

I originally was thinking of using a vecify command (would have cost a lot of bytes) but then I remembered I had the nice little υ.

Zacharý

Posted 2016-03-22T17:45:18.033

Reputation: 5 710

0

AHK, 37 bytes

Loop,Parse,1
Send,%A_LoopField%{VK20}

The variable 1 is the first passed argument. {VK20} is a space.

Engineer Toast

Posted 2016-03-22T17:45:18.033

Reputation: 5 769

0

Taxi, 363 bytes

Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Chop Suey.[a]Go to Chop Suey:n 1 r 1 l 4 r 1 l.Switch to plan "z" if no one is waiting.Pickup a passenger going to Post Office.Go to Zoom Zoom:n 1 l 3 r." " is waiting at Writer's Depot.Go to Writer's Depot:w.Pickup a passenger going to Post Office.Go to Post Office:n 1 r 2 r 1 l.Switch to plan "a".[z]

Try it online!

Un-golfed / formatted:

Go to Post Office: west 1st left 1st right 1st left.
Pickup a passenger going to Chop Suey.
[a]
Go to Chop Suey: north 1st right 1st left 4th right 1st left.
Switch to plan "z" if no one is waiting.
Pickup a passenger going to Post Office.
Go to Zoom Zoom: north 1st left 3rd right.
" " is waiting at Writer's Depot.
Go to Writer's Depot: west.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st right 2nd right 1st left.
Switch to plan "a".
[z]

Nothing fancy here. It's just an old challenge that Taxi is able to easily handle, a rare thing at times.

Engineer Toast

Posted 2016-03-22T17:45:18.033

Reputation: 5 769

0

Rust, 49 Bytes

|mut x:String|{x.replace(""," ");x.remove(0);x}

it is an anonymous function, or lambda. It gets input from x, then modifies and returns it.

Håvard Nygård

Posted 2016-03-22T17:45:18.033

Reputation: 341

0

SNOBOL4 (CSNOBOL4), 71 bytes

	I =INPUT
S	I LEN(1) . X REM . I :F(O)
	O =O X ' ' :(S)
O	OUTPUT =O
END

Try it online!

Giuseppe

Posted 2016-03-22T17:45:18.033

Reputation: 21 077

0

Swift, 45 bytes

{$0.map{"\($0) "}.joined()}as(String)->String

Try it online!

Herman L

Posted 2016-03-22T17:45:18.033

Reputation: 3 611

0

Standard ML (Mlton), 34 bytes

String.translate(fn c=>str c^" ");

Try it online! It turns out translate : (char -> string) -> string -> string from the String library is exactly the function needed for this task. The lambda fn c=>str c^" " takes a char, converts it to a string with the function str and prepends it to the string " ". translate applies this function to all chars and combines the resulting strings to a single string.


Other versions I found before stumbling over the translate function:

String.concatWith" "o map str o explode;
concat o map(fn c=>str c^" ")o explode;
foldr(fn(c,s)=>str c^" "^s)""o explode;
String.concatWithMap" "str o explode;    (* only in SML/NJ *)

Laikoni

Posted 2016-03-22T17:45:18.033

Reputation: 23 676

0

SmileBASIC, 39 bytes

LINPUT A$WHILE""<A$?SHIFT(A$);" ";
WEND

12Me21

Posted 2016-03-22T17:45:18.033

Reputation: 6 110

0

Ahead, 8 bytes

~Wi@j '~

Try it online!

snail_

Posted 2016-03-22T17:45:18.033

Reputation: 1 982

0

C# (Visual C# Interactive Compiler), 44 bytes

for(int c;-1<(c=Read());Write((char)c+" "));

Try it online!

Not the first C# submission :) But it follows the challenge to the letter in terms of using STDIN and STDOUT.

dana

Posted 2016-03-22T17:45:18.033

Reputation: 2 541

0

Perl 6, 14 bytes

put get.comb,$

Try it online!

Prints a trailing newline.

Explanation:

put             # print to stdout
    get.comb    # the list of characters in the input, 
            ,$  # And an empty string
put             # Implicitly separated by spaces

Jo King

Posted 2016-03-22T17:45:18.033

Reputation: 38 234

0

Japt -P, 2 bytes

ïS

Try it

ï      :Cartesian product with
 S     :  Space

Shaggy

Posted 2016-03-22T17:45:18.033

Reputation: 24 623

0

C#, 105 bytes

public class P{public static void Main(string[]a){foreach(char c in a[0]){System.Console.Write(c+" ");}}}

EDIT: Removed space between string[] and a, also removed ToString as its not crucial saving a total of 12 bytes

canttalkjustcode

Posted 2016-03-22T17:45:18.033

Reputation: 131

This is a snippet. Answers on this site are required to be full programs or functions. – pppery – 2019-08-19T20:54:35.587

Fixed it, sorry!!! – canttalkjustcode – 2019-08-19T23:11:01.940

The parameter passed through string[] a in C# is an array of all arguments. I just get index 0 (first parameter). That's valid input. – canttalkjustcode – 2019-08-19T23:37:06.693

Sorry, I got confused by the fact that you failed to update the try online link when you edited your code. – pppery – 2019-08-19T23:37:57.047

You can save 14 bytes by removing public keywords – Jirka Picek – 2020-01-02T11:20:38.920

0

C# (Visual C# Interactive Compiler), 44 bytes

Version reading an argument

Write(string.Join(" ",Args[0].ToList())+" ")

Try it online!

47 bytes

Version reading standard input

Write(string.Join(" ",ReadLine().ToList())+" ")

Try it online!

Jirka Picek

Posted 2016-03-22T17:45:18.033

Reputation: 171

0

Elixir, 55 43

Regex.replace(~r/(.)\n?/,IO.gets(""),"\\0 ")

Sadly, stripping the newline is pretty costly in terms of characters (not sure if I can remove it).

Ven

Posted 2016-03-22T17:45:18.033

Reputation: 3 382

0

Japt, 5 bytes

U¬¸+S

Try it here.

Mama Fun Roll

Posted 2016-03-22T17:45:18.033

Reputation: 7 234

0

Javascript, 35 chars

Full program

alert(prompt().replace(/./g,"$& "))

Javascript ES6, 24 chars

Just a function

s=>s.replace(/./g,"$& ")

Qwertiy

Posted 2016-03-22T17:45:18.033

Reputation: 2 697

As we are using a leaderboard right now, would you mind modifying your title for just "Javascript", as it will actually be considered as an other language. – Katenkyo – 2016-03-23T09:50:35.327

@Katenkyo, updated – Qwertiy – 2016-03-23T09:54:26.570

0

Befunge-93, 18 bytes

>~:1`#v_@
^," ",<

Jevado

Posted 2016-03-22T17:45:18.033

Reputation: 111

0

Python 2.7, 62 Bytes

Yes, I know this is not as competitive with most of the other answers, but I wanted to use zip in some sort of way.

i=input();j=''.join;print(j([j(z)for z in zip(i,' '*len(i))]))

Mr Public

Posted 2016-03-22T17:45:18.033

Reputation: 669

0

Befunge-98, 21 bytes

>  ~:av
^,*84,w
@,*84,<

Lengthier than one already present but has the ending space requested by OP.

Luke Marlin

Posted 2016-03-22T17:45:18.033

Reputation: 401

0

Matlab/Octave, 51 bytes

s=s(.5:.5:length(s))
s(1:2:length(s))=' '

Ben Perlin

Posted 2016-03-22T17:45:18.033

Reputation: 69

0

Octave, 18 bytes

@(s)[s;32+0*s](:)'

Creates an anonymous function. Can then be run using ans('input string')

Same rationale as my MATL answer. Takes advantage of the fact that you can flatten (:) an array in Octave prior to assignment to a variable.

Suever

Posted 2016-03-22T17:45:18.033

Reputation: 10 257

0

MATLAB, 25 bytes

@(s)reshape([s;0*s],1,[])

Creates an anonymous function that can be then called using ans('input string').

Exploits that fact that a null character is displayed as a space in MATLAB. Therefore [s;0*s] appends a new row that is all spaces. Then using reshape flattens this back out into a string but the spaces are inter-spersed due to the row-major ordering.

Suever

Posted 2016-03-22T17:45:18.033

Reputation: 10 257