49
\$\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>

Alex A.
24.8k5 gold badges39 silver badges120 bronze badges
asked Mar 22, 2016 at 17:45
\$\endgroup\$
10
  • 8
    \$\begingroup\$ Usually you should allow functions too, or you exclude a lot of languages (e.g. JavaScript). \$\endgroup\$ 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\$ Commented Mar 22, 2016 at 21:22
  • 65
    \$\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

151 Answers 151

0
\$\begingroup\$

Japt, 5 bytes

U¬ ̧+S

Try it here.

answered Mar 23, 2016 at 3:15
\$\endgroup\$
0
\$\begingroup\$

Matlab/Octave, 51 bytes

s=s(.5:.5:length(s))
s(1:2:length(s))=' '
answered Mar 24, 2016 at 3:56
\$\endgroup\$
0
\$\begingroup\$

Befunge-93, 18 bytes

>~:1`#v_@
^," ",<
\$\endgroup\$
0
\$\begingroup\$

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.

answered Apr 16, 2016 at 18:13
\$\endgroup\$
0
\$\begingroup\$

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.

answered Apr 16, 2016 at 18:20
\$\endgroup\$
0
\$\begingroup\$

AHK, 37 bytes

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

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

answered Jul 26, 2017 at 16:09
\$\endgroup\$
0
\$\begingroup\$

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.

answered Jul 26, 2017 at 16:15
\$\endgroup\$
0
\$\begingroup\$

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

answered Jul 26, 2017 at 15:59
\$\endgroup\$
0
\$\begingroup\$

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))]))
Riker
7,9284 gold badges40 silver badges73 bronze badges
answered Mar 23, 2016 at 12:52
\$\endgroup\$
0
\$\begingroup\$

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.

answered Dec 18, 2017 at 18:32
\$\endgroup\$
0
\$\begingroup\$

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!

answered Dec 18, 2017 at 18:43
\$\endgroup\$
0
\$\begingroup\$

Swift, 45 bytes

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

Try it online!

answered Dec 18, 2017 at 19:08
\$\endgroup\$
0
\$\begingroup\$

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

answered Jul 3, 2017 at 18:48
\$\endgroup\$
0
\$\begingroup\$

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 *)
answered Jan 26, 2018 at 15:04
\$\endgroup\$
0
\$\begingroup\$

SmileBASIC, 39 bytes

LINPUT A$WHILE""<A$?SHIFT(A$);" ";
WEND
answered Mar 3, 2018 at 17:01
\$\endgroup\$
0
\$\begingroup\$

Ahead, 8 bytes

~Wi@j '~

Try it online!

answered Feb 11, 2019 at 6:26
\$\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.

answered Feb 11, 2019 at 23:35
\$\endgroup\$
0
\$\begingroup\$

Japt -P, 2 bytes

ïS

Try it

ï :Cartesian product with
 S : Space
answered Feb 12, 2019 at 17:12
\$\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).

answered Mar 22, 2016 at 21:14
\$\endgroup\$
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\$
5
  • \$\begingroup\$ This is a snippet. Answers on this site are required to be full programs or functions. \$\endgroup\$ Commented Aug 19, 2019 at 20:54
  • \$\begingroup\$ Fixed it, sorry!!! \$\endgroup\$ Commented Aug 19, 2019 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\$ Commented Aug 19, 2019 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\$ Commented Aug 19, 2019 at 23:37
  • \$\begingroup\$ You can save 14 bytes by removing public keywords \$\endgroup\$ Commented Jan 2, 2020 at 11:20
0
\$\begingroup\$

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!

answered Jan 2, 2020 at 8:24
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 3 bytes

ðâJ

Try it online!

ðâJ # full program
 J # join...
 â # cartesian product of...
 # implicit input...
 â # and...
ð # " "
 # implicit output
answered Feb 2, 2021 at 18:43
\$\endgroup\$
0
\$\begingroup\$

BRASCA, 10 bytes

![aEmmA{]x

Try it online!

Explanation

! - Push stack length
 [a A{] - For i in range(0,stack_length)
 E - Push a space
 mm - Shift the stack twice
 x - Remove the excess 0
<implicit> - Output the stack reversed
answered Feb 12, 2021 at 10:31
\$\endgroup\$
0
\$\begingroup\$

Thunno 2 J, 2 bytes

ðṖ

Attempt This Online!

Port of Dennis's Jelly answer: cartesian product with space. J flag joins the list.

answered May 28, 2023 at 18:58
\$\endgroup\$
0
\$\begingroup\$

Python, 30 Bytes

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

T r y i t o n l i n e !

answered May 29, 2023 at 13:24
\$\endgroup\$
0
\$\begingroup\$

Rockstar, 43 bytes

listen to S
cut S
join S with " "
say S+" "

Try it (Code will need to be pasted in)

answered Jun 1, 2023 at 15:40
\$\endgroup\$
0
\$\begingroup\$

Nibbles, 3.5 bytes (7 nibbles)

+.@:$" "

Attempt This Online!

Explanation

+.@:$" "
 @ First line of stdin as a string (list of chars)
 . Map this function:
 $ To each char,
 : Append
 " " A space
+ Concatenate the resulting list of strings together
answered Jun 1, 2023 at 17:26
\$\endgroup\$
0
\$\begingroup\$

ARBLE, 17 bytes

gsub(s,".","%1 ")

Full Program.

Try it online!

answered Sep 3, 2023 at 22:40
\$\endgroup\$
0
\$\begingroup\$

Swift 5.9, 38 bytes

let f={(0ドル+"").map{" \(0ドル)"}.joined()}
answered Mar 15, 2024 at 12:26
\$\endgroup\$
0
\$\begingroup\$

jBasher2, 250 bytes

create a with type string
create b with type number
create c with type number
set 0 to c
ask for input
set that to a
get length of a
set that to b
while c < b
get item from a at c
output inline that
output inline " "
add 1 by c
set that to c
endwhile

pretty self explanatory lols

answered Jan 21 at 18:25
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.