44
\$\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\$
  • 6
    \$\begingroup\$ Usually you should allow functions too, or you exclude a lot of languages (e.g. JavaScript). \$\endgroup\$ – wizzwizz4 Mar 22 '16 at 18:00
  • 8
    \$\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 Mar 22 '16 at 21:22
  • 52
    \$\begingroup\$ That is not what fullwidth text is. \$\endgroup\$ – BlueRaja - Danny Pflughoeft Mar 22 '16 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\$ – Ludovic Frérot Mar 23 '16 at 9:27
  • 2
    \$\begingroup\$ @LudovicFrérot Actually, these are not ideograms, these are chinese english letters. \$\endgroup\$ – Erik the Outgolfer Jul 1 '16 at 8:29

128 Answers 128

0
\$\begingroup\$

Ahead, 8 bytes

~Wi@j '~

Try it online!

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

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.

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

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

Japt -P, 2 bytes

ïS

Try it

ï      :Cartesian product with
 S     :  Space
\$\endgroup\$
0
\$\begingroup\$

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

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

Perl 6, 12 + 1 flag = 13 bytes

s:g/(.)/$1 /

Only uses Perl 6 Regexes features, not Perl 5.

example:

perl6 -pe 's:g/(.)/$0 /' <<< abc
\$\endgroup\$
  • \$\begingroup\$ right, I inversed the numbers here and in the perl 5 solution. Thanks! (numbering in 5 starts at 1) \$\endgroup\$ – Ven Mar 22 '16 at 21:05
  • 1
    \$\begingroup\$ those special variables were removed. (you can still get to them, but it'd take more characters) \$\endgroup\$ – Ven Mar 22 '16 at 21:07
  • \$\begingroup\$ Does Perl 6 have \K? If so you should be able to use /.\K/ /. \$\endgroup\$ – Martin Ender Mar 24 '16 at 14:04
  • \$\begingroup\$ @MartinBüttner it doesn't :) \$\endgroup\$ – Ven Mar 24 '16 at 15:25
0
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ This is a snippet. Answers on this site are required to be full programs or functions. \$\endgroup\$ – pppery Aug 19 at 20:54
  • \$\begingroup\$ Fixed it, sorry!!! \$\endgroup\$ – canttalkjustcode Aug 19 at 23:11
  • \$\begingroup\$ 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. \$\endgroup\$ – canttalkjustcode Aug 19 at 23:37
  • \$\begingroup\$ Sorry, I got confused by the fact that you failed to update the try online link when you edited your code. \$\endgroup\$ – pppery Aug 19 at 23:37
0
\$\begingroup\$

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!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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