47
\$\begingroup\$

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>

\$\endgroup\$
11
  • 8
    \$\begingroup\$ Usually you should allow functions too, or you exclude a lot of languages (e.g. JavaScript). \$\endgroup\$
    – wizzwizz4
    Commented Mar 22, 2016 at 18:00
  • 10
    \$\begingroup\$ 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). \$\endgroup\$
    – Dennis
    Commented Mar 22, 2016 at 21:22
  • 64
    \$\begingroup\$ That is not what fullwidth text is. \$\endgroup\$ Commented Mar 22, 2016 at 21:53
  • 4
    \$\begingroup\$ @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 \$\endgroup\$ Commented Mar 23, 2016 at 9:27
  • 3
    \$\begingroup\$ @LudovicFrérot Actually, these are not ideograms, these are chinese english letters. \$\endgroup\$ Commented Jul 1, 2016 at 8:29

148 Answers 148

1
2 3 4 5
29
\$\begingroup\$

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!

\$\endgroup\$
14
  • 1
    \$\begingroup\$ ⁶ takes up three bytes in UTF-8. \$\endgroup\$
    – Jess Smith
    Commented Mar 22, 2016 at 18:02
  • 13
    \$\begingroup\$ @JessSmith Jelly uses its own code page: github.com/DennisMitchell/jelly/blob/master/docs/code-page.md \$\endgroup\$ Commented Mar 22, 2016 at 18:02
  • 1
    \$\begingroup\$ @AandN Put it in the answer, not a comment. \$\endgroup\$
    – mbomb007
    Commented Mar 22, 2016 at 20:08
  • 3
    \$\begingroup\$ @mbomb007 It's right in the header. \$\endgroup\$
    – Adnan
    Commented Mar 22, 2016 at 20:09
  • 5
    \$\begingroup\$ @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. \$\endgroup\$
    – mbomb007
    Commented Mar 22, 2016 at 20:10
28
\$\begingroup\$

Python 3.5, 18 bytes

print(*input(),'')

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

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

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.

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

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.

\$\endgroup\$
1
  • \$\begingroup\$ Interesting that Haskell and Jelly are kind of doing the same thing here, since the list monad acts similarly to a Cartesian product. \$\endgroup\$
    – ballesta25
    Commented Mar 24, 2016 at 5:43
9
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ @FryAmTheEggman I prefer to use $0. It's the same thing, but more common. \$\endgroup\$
    – mbomb007
    Commented Mar 22, 2016 at 19:42
  • \$\begingroup\$ Here's a useful reference to go along with Retina's wiki: msdn.microsoft.com/en-us/library/… \$\endgroup\$
    – mbomb007
    Commented Mar 22, 2016 at 19:45
6
\$\begingroup\$

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
                         ╰────────╯
\$\endgroup\$
0
6
\$\begingroup\$

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

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

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 ")
\$\endgroup\$
4
  • \$\begingroup\$ The question specified that the input must be from STDIN. \$\endgroup\$
    – EMBLEM
    Commented Mar 22, 2016 at 20:17
  • \$\begingroup\$ I could add one for you, if that's ok. \$\endgroup\$
    – Blue
    Commented Mar 22, 2016 at 21:26
  • \$\begingroup\$ I've added a STDIN version now (and used the clever regexplace shooqie figured out). \$\endgroup\$
    – CAD97
    Commented Mar 23, 2016 at 1:47
  • 1
    \$\begingroup\$ No need for parentheses in your regex. Also removed an extra space between arguments to replaceAll. \$\endgroup\$ Commented Aug 19, 2019 at 15:53
4
\$\begingroup\$

Java, 92

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

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.

\$\endgroup\$
0
4
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ you can save a byte with @.Uoi?So \$\endgroup\$
    – MickyT
    Commented Jul 3, 2017 at 22:07
4
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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
\$\endgroup\$
3
\$\begingroup\$

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
\$\endgroup\$
2
  • 1
    \$\begingroup\$ ðâJ non-competing. \$\endgroup\$ Commented Jan 12, 2017 at 16:03
  • \$\begingroup\$ @Kevin That doesn't output the trailing space. \$\endgroup\$
    – Makonede
    Commented Feb 2, 2021 at 18:43
3
\$\begingroup\$

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
\$\endgroup\$
0
3
\$\begingroup\$

GolfScript, 6 bytes

' ':n*

Try it online!

\$\endgroup\$
3
\$\begingroup\$

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

\$\endgroup\$
3
\$\begingroup\$

Pyth, 5 4 bytes

Thanks to @FryAmTheEggman for saving a byte.

s*zd

Try it online here.

\$\endgroup\$
2
  • \$\begingroup\$ Jesus hecking christ how the heck \$\endgroup\$
    – Tornado547
    Commented Dec 14, 2017 at 19:53
  • \$\begingroup\$ Alternative 4-byter: s+R; \$\endgroup\$
    – Sok
    Commented Feb 14, 2019 at 13:56
3
\$\begingroup\$

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
\$\endgroup\$
3
\$\begingroup\$

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).
\$\endgroup\$
3
\$\begingroup\$

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 . 
\$\endgroup\$
2
  • \$\begingroup\$ I haven't seen this language before. Link to the interpreter? \$\endgroup\$ Commented Mar 26, 2016 at 4:57
  • 1
    \$\begingroup\$ 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”. \$\endgroup\$
    – manatwork
    Commented Mar 26, 2016 at 13:52
3
\$\begingroup\$

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
\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

brainfuck, 24 22 bytes

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

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

Try it online

\$\endgroup\$
1
  • \$\begingroup\$ ,[.>>-[-[-<]>>+<]>-.,] saves two bytes. \$\endgroup\$
    – Dennis
    Commented Jul 1, 2016 at 22:15
3
\$\begingroup\$

PHP, 31 bytes

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

takes input from command line argument.

\$\endgroup\$
3
\$\begingroup\$

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!

\$\endgroup\$
3
\$\begingroup\$

Python 2, 27 25 24 bytes

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

Shorter than Raffi's answer...

-1 thanks to 60919 (FlipTack).

\$\endgroup\$
1
  • \$\begingroup\$ If functions are allowed then lambda x:' '.join(x)+' ' is 1 byte shorter. \$\endgroup\$
    – FlipTack
    Commented Jan 12, 2017 at 20:06
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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

\$\endgroup\$
12
  • \$\begingroup\$ 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 \$\endgroup\$
    – Josh
    Commented Mar 22, 2016 at 19:59
  • \$\begingroup\$ @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. \$\endgroup\$
    – SBI
    Commented Mar 22, 2016 at 20:04
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Mar 22, 2016 at 20:06
  • \$\begingroup\$ @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. \$\endgroup\$
    – SBI
    Commented Mar 22, 2016 at 20:10
  • \$\begingroup\$ Generally, if it works with Ideone it's ok :) \$\endgroup\$ Commented Mar 22, 2016 at 20:12
1
2 3 4 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.