# Full Width Text

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.

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>

• Usually you should allow functions too, or you exclude a lot of languages (e.g. JavaScript). – wizzwizz4 Mar 22 '16 at 18:00
• 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 Mar 22 '16 at 21:22
• Ｔｈａｔ　ｉｓ　ｎｏｔ　ｗｈａｔ　ｆｕｌｌｗｉｄｔｈ　ｔｅｘｔ　ｉｓ． – BlueRaja - Danny Pflughoeft Mar 22 '16 at 21:53
• @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 Mar 23 '16 at 9:27
• @LudovicFrérot Actually, these are not ideograms, these are chinese english letters. – Erik the Outgolfer Jul 1 '16 at 8:29

## Ruby, 24 15 bytes

gsub /./,'\0 '


Requires the -p flag (byte added).

Thanks to xsot for 9 bytes!

• Using -p saves 8 bytes – xsot Mar 23 '16 at 1:03
• @xsot Thanks, I didn't even know that flag existed! – Doorknob Mar 23 '16 at 1:10
• 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 Mar 23 '16 at 1:28
• @xsot Comma's not an operator in Ruby. Parenthesis are frequently optional, except in certain contexts. – Doorknob Mar 23 '16 at 1:29

# Pyth, 5 4 bytes

Thanks to @FryAmTheEggman for saving a byte.

s*zd

• Jesus hecking christ how the heck – Tornado547 Dec 14 '17 at 19:53
• Alternative 4-byter: s+R; – Sok Feb 14 at 13:56

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

• Wow, sleek usage of " and wrap-around – daniero Mar 23 '16 at 18:21
• -1 Byte – Jo King Dec 19 '17 at 7:32

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

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

# C, 48 bytes

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


Try it online

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

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

# Jolf, 7 bytes

Try it here!

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


# RETURN, 10 bytes

""¨{' °},


Try it here.

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

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


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

• Update this post later? – CalculatorFeline Mar 23 '16 at 2:25
• @CatsAreFluffy oh, my bad, I forgot, will do now. – GamrCorps Mar 23 '16 at 2:38

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