# 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). 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). Mar 22 '16 at 21:22
• Ｔｈａｔ　ｉｓ　ｎｏｔ　ｗｈａｔ　ｆｕｌｌｗｉｄｔｈ　ｔｅｘｔ　ｉｓ． 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 Mar 23 '16 at 9:27
• @LudovicFrérot Actually, these are not ideograms, these are chinese english letters. Jul 1 '16 at 8:29

# Jelly, 53 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!

• ⁶ takes up three bytes in UTF-8. Mar 22 '16 at 18:02
• @JessSmith Jelly uses its own code page: github.com/DennisMitchell/jelly/blob/master/docs/code-page.md Mar 22 '16 at 18:02
• @AandN Put it in the answer, not a comment. Mar 22 '16 at 20:08
• @mbomb007 It's right in the header. Mar 22 '16 at 20:09
• @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. Mar 22 '16 at 20:10

# Python 3.5, 18 bytes

print(*input(),'')


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

• print(*input(),end=' ') would be portable, but it's not very golfy... Mar 22 '16 at 20:35
• MFW the first use of my PEP I see in the wild is on Code Golf. Mar 23 '16 at 8:15
• Does this have a space after the last character? Jun 4 '17 at 16:15

# Hexagony, 211312 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:

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:

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

Using Timwi's amazing HexagonyColorer for making the diagrams.

• Uh, I was golfing while you edited. Oops. 10: P,<0/*;@.> Mar 22 '16 at 19:33
• @FryAmTheEggman Hahaha, let's make a new explanation then :p. Mar 22 '16 at 19:39
• P,<<>0;@>* is also 10, but unfortunately I don't think it helps in shaving off another byte. Mar 23 '16 at 6:54
• @MartinBüttner Oh, that's a shame. I doubt if it's possible to shave off another byte, but it seems unlikely. Mar 24 '16 at 16:03
• Is HexagonyColorer now animated? Jun 4 '17 at 16:15

((:" ")=<<)


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.

• Interesting that Haskell and Jelly are kind of doing the same thing here, since the list monad acts similarly to a Cartesian product. Mar 24 '16 at 5:43

# 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. • @FryAmTheEggman I prefer to use $0. It's the same thing, but more common. Mar 22 '16 at 19:42
• Here's a useful reference to go along with Retina's wiki: msdn.microsoft.com/en-us/library/… Mar 22 '16 at 19:45

# 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

• [...s,].join   perhaps?
– Neil
Mar 22 '16 at 18:39
• Even better [...s,,].join ... Jul 1 '16 at 13:27
• @edc65 Doesn't work in latest Firefox or Chrome? I just get the join function as the return, as I would expect. Jul 1 '16 at 15:55
• @Mwr247 after the join you must put the rest of your code, that's why I put ellipsis (...). It's just 1 byte saving Jul 1 '16 at 23:45
• @edc65 may have been too lazy to work out how to type the   in a comment.
– Neil
Jul 9 '16 at 21:11

# ><>, 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:
'      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

• i:0(?;o 'o for 10 Mar 23 '16 at 1:51
• In fact, io 'o works too, erroring out. Mar 23 '16 at 1:52
• @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? Mar 23 '16 at 1:56
• ' 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. Mar 23 '16 at 1:57
• @Sp3000 Got it. So that's also cyclical. Thanks a lot for the suggestion and explanation! Mar 23 '16 at 1:58

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

• The question specified that the input must be from STDIN. Mar 22 '16 at 20:17
• I could add one for you, if that's ok.
– Blue
Mar 22 '16 at 21:26
• I've added a STDIN version now (and used the clever regexplace shooqie figured out). Mar 23 '16 at 1:47
• No need for parentheses in your regex. Also removed an extra space between arguments to replaceAll. Aug 19 '19 at 15:53

class T{public static void main(String[]A){System.out.print(A[0].replaceAll("(.)","$0 "));}}  # 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 ╰────────╯  # 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. # 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. • you can save a byte with @.Uoi?So Jul 3 '17 at 22:07 # 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. # 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  • ðâJ non-competing. Jan 12 '17 at 16:03 • @Kevin That doesn't output the trailing space. Feb 2 '21 at 18:43 # 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  # GolfScript, 6 bytes ' ':n*  Try it online! ### 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

# Pyth, 5 4 bytes

Thanks to @FryAmTheEggman for saving a byte.

s*zd

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

# 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
duplicate
# 0 1
-
integer
TARDIS =
TARDIS if
opening
TARDIS landing
# 20
pop
psychic_paper flush


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


# 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 .  • I haven't seen this language before. Link to the interpreter? Mar 26 '16 at 4:57 • 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”. Mar 26 '16 at 13:52 # 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  ## 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. # brainfuck, 24 22 bytes Simple example using the shortest known 32 for the space character(s). ,[.>>-[-[-<]>>+<]>-.,]  Try it online • ,[.>>-[-[-<]>>+<]>-.,] saves two bytes. Jul 1 '16 at 22:15 # PHP, 31 bytes <?=chunk_split($argv[1],1," ");


takes input from command line argument.

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

# Python 2, 2725 24 bytes

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


-1 thanks to 60919 (FlipTack).

• If functions are allowed then lambda x:' '.join(x)+' ' is 1 byte shorter. Jan 12 '17 at 20:06

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

# 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

• 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: codegolf.stackexchange.com/q/2203/13877
– Josh
Mar 22 '16 at 19:59
• @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
Mar 22 '16 at 20:04
• 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. Mar 22 '16 at 20:06
• @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
Mar 22 '16 at 20:10
• Generally, if it works with Ideone it's ok :) Mar 22 '16 at 20:12

# R, 36 bytes

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


Example:

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

• You don't need sep=" ", so this can be much shorter: Try it online! Mar 9 '18 at 16:50