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>
-
8\$\begingroup\$ Usually you should allow functions too, or you exclude a lot of languages (e.g. JavaScript). \$\endgroup\$wizzwizz4– wizzwizz42016年03月22日 18:00:20 +00:00Commented 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– Dennis2016年03月22日 21:22:58 +00:00Commented Mar 22, 2016 at 21:22
-
65\$\begingroup\$ That is not what fullwidth text is. \$\endgroup\$BlueRaja - Danny Pflughoeft– BlueRaja - Danny Pflughoeft2016年03月22日 21:53:15 +00:00Commented 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\$Ludovic Frérot– Ludovic Frérot2016年03月23日 09:27:15 +00:00Commented Mar 23, 2016 at 9:27
-
3\$\begingroup\$ @LudovicFrérot Actually, these are not ideograms, these are chinese english letters. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年07月01日 08:29:17 +00:00Commented Jul 1, 2016 at 8:29
151 Answers 151
R, 36 bytes
cat(strsplit(readline(),"")[[1]],"")
Example:
> cat(strsplit(readline(),"")[[1]],"")
Hello R!
H e l l o R !
-
1\$\begingroup\$ You don't need
sep=" ", so this can be much shorter: Try it online! \$\endgroup\$Giuseppe– Giuseppe2018年03月09日 16:50:13 +00:00Commented Mar 9, 2018 at 16:50
Perl 6, 14 bytes
put get.comb,$
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
Ruby, (削除) 24 (削除ここまで) 15 bytes
gsub /./,'0円 '
Requires the -p flag (byte added).
Thanks to xsot for 9 bytes!
-
\$\begingroup\$ Using
-psaves 8 bytes \$\endgroup\$xsot– xsot2016年03月23日 01:03:54 +00:00Commented Mar 23, 2016 at 1:03 -
\$\begingroup\$ @xsot Thanks, I didn't even know that flag existed! \$\endgroup\$Doorknob– Doorknob2016年03月23日 01:10:02 +00:00Commented Mar 23, 2016 at 1:10
-
\$\begingroup\$ 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. \$\endgroup\$xsot– xsot2016年03月23日 01:28:07 +00:00Commented Mar 23, 2016 at 1:28
-
1\$\begingroup\$ @xsot Comma's not an operator in Ruby. Parenthesis are frequently optional, except in certain contexts. \$\endgroup\$Doorknob– Doorknob2016年03月23日 01:29:31 +00:00Commented Mar 23, 2016 at 1:29
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
-
\$\begingroup\$ Wow, sleek usage of
"and wrap-around \$\endgroup\$daniero– daniero2016年03月23日 18:21:54 +00:00Commented Mar 23, 2016 at 18:21 -
J, 8 bytes
,@,.&' '
,. is the stitch command, and ' ' , 'string' creates a table with a space following each character. , takes these items out of the table when used as a monad, and @ composes this function with our other function. Use:
fullWidth =: ,@,.&' '
fullWidth 'this text is full width!'
fullWidth 'this text is full width!'
t h i s t e x t i s f u l l w i d t h !
Great thanks to Zgarb who helped me make this answer.
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)
, Read char from STDIN
. 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.
Sed, 8 bytes
's/$*/ /g'
Can be run from bash as
$ sed 's/$*/ /g' <<< "Full Width Text."
Outputs
F u l l w i d t h t e x t .
-
\$\begingroup\$ Nice answer, but i think you mean '/g/ in the test case not '/f'. +1 though. \$\endgroup\$Riker– Riker2016年03月24日 02:47:22 +00:00Commented Mar 24, 2016 at 2:47
-
\$\begingroup\$ Thank you, 'f' is right next to 'g' on the dvorak keyboard \$\endgroup\$Ben Perlin– Ben Perlin2016年03月24日 03:37:11 +00:00Commented Mar 24, 2016 at 3:37
-
1\$\begingroup\$ My understanding is that a leading space is not permitted. \$\endgroup\$Neil– Neil2016年03月24日 10:55:00 +00:00Commented Mar 24, 2016 at 10:55
-
\$\begingroup\$ I concur with @Neil. The challenge specifically mentions a trailing space. Therefore the
sedcommand must be something likes/./& /g, which is still 8 Bytes nevertheless. \$\endgroup\$Kai Burghardt– Kai Burghardt2024年03月15日 14:54:58 +00:00Commented Mar 15, 2024 at 14:54
beeswax, 20 bytes
p?Cy ?<~1V_
>` `Ag'b
Example:
julia> beeswax("Full Width Text.bswx")
sHello, World!
H e l l o , W o r l d !
Program finished!
Explanation:
lstack gstack
_ [0,0,0]• []• create bee
V [0,0,0]• [72,101,108,108,111,10]• read in string to gstack
1 [0,0,1]• lstack 1st=1
~ [0,1,0]• flip lstack 1st and 2nd
< [0,0,0]• (1) redirect to left
? [0,1,0]• [72,101,108,108,111]• pop gstack top value (\n)
y [0,1,0]• [101,108,108,111,72]• rotate gstack down by lstack[-,steps,depth]•
depth=0 defaults to full stack length
C STDOUT='H' print gstack top value as Char to STDOUT
? [101,108,108,111]• pop gstack top value
p redirect to lower left
> redirect to right
` ` STDOUT=' ' print space char to STDOUT
A [101,108,108,111,4]• push gstack length on top of gstack
g [0,1,4]• lstack 1st=gstack top
' skip next if lstack 1st=0
b redirect to upper left
< loop back to (1)
? [101,108,108,111]•
y [0,1,4]• [108,108,111,101]•
C STDOUT='e'
? [108,108,111]•
p
>` ` STDOUT=' '
. . .
. . .
. . .
Hoon, 41 bytes
|*
*
`tape`(turn +< |=(@ (cat 3 +< ' ')))
Takes advantage of not having to specify the tape of a wet gate (|*), and that arguments are places at +< to prevent having to name them.
There are actually two different types of strings in Hoon: tapes, and cords. tapes are (list @tD), while cords are simply @t.
Think the difference between a vector and an array: tapes can be indexed into and manipulated easily, while cords are "static" and basically just bignums.
This entry maps over the characters in the tape it gets as input, and adds on the value of ' ' to the end of the atom and then casts the result back to a tape.
Technically, this should probably be a type error: tape is a list of characters, and we are stuffing two in the space of only one. Luckily, while Hoon has syntax to say what you should expect the size of an atom to be, it doesn't actually enforce that expectation. Even slamming a too-big atom with a specific sized verification gate doesn't give back the default value like it should. Naturally, we abuse this and it even prints correctly in the console, as long as you don't try to full-width text any UTF-8 characters.
Usage:
> %. "Full width text is text that has a space after every character, including the last one."
|*
*
`tape`(turn +< |=(@ (cat 3 +< ' ')))
"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 . "
Pyke, 5 bytes
dm+s_
Explanation:
d - load ' ' onto the stack
m+ - map(add, eval_input_or_not(), " ")
s - "".join(^)
_ - ^[::-1]
At the moment Pyke has a bug where if map is given a string, it reverses it :(
Or with a new fixed version, 3 bytes
dL+
left_map(input(), " ", add)
Carrot, 13 bytes, non-competing
#^//./gS" "^
(note trailing space in code)
(to be able to see the trailing space in the output, open up the JS console and select the outputted text in the console output)
Explanation
Note: the "stack" is actually just a string (not an array) in Carrot
#^ // pushes the input `#` to the stack, now the stack == input
/ // split on:
/./g // every character in the stack
Now the program is in arrayMode, meaning that the stack is now an array (or stackA to be more precise)
S" " // join on spaces
Now we got spaces after every character except for the last one
^<space> // append a space to the stack
And then the stack is implicitly outputted
-
\$\begingroup\$ I just accidentally posted this solution without seeing yours. Is there no way to convert to array mode with
Aby splitting on nothing soHibecomes[ "H", "i" ]? I though no argument would do it or a space but I was wrong. \$\endgroup\$TheLethalCoder– TheLethalCoder2017年07月26日 16:26:18 +00:00Commented Jul 26, 2017 at 16:26 -
\$\begingroup\$ @TheLethalCoder Another one of the reasons I am doing the rewrite of Carrot, the current interpreter does a terrible job of parsing and everything is just a bunch of hacks taped very loosely... In the new interpreter,
Ais planned take a string as an argument, where this string can be of any length, in which case what you are suggesting should work. \$\endgroup\$user41805– user418052017年07月26日 16:36:32 +00:00Commented Jul 26, 2017 at 16:36
q/kdb+, 12 bytes
Solution:
raze{x,'" "}
Example:
q)raze{x,'" "}"Hello World!"
"H e l l o W o r l d ! "
Explanation:
,' / join (,) each left ("H", "e", "l"...) with each right (" ")
raze / reduce list
Notes:
Would be 9 bytes doing it more directly rather than as a lambda function:
q)raze"Hello World!",'" "
"H e l l o W o r l d ! "
APL (Dyalog), 4 bytes
Requires ⎕ML←0 which used to be standard
,⍪,∊
, ravel (flatten)
⍪ the columnified argument
, followed by
∊ the prototypes (one space per character)
-
\$\begingroup\$ Can you explain why this needs to be encoded in UTF-8? \$\endgroup\$Adalynn– Adalynn2017年07月26日 16:01:22 +00:00Commented Jul 26, 2017 at 16:01
-
\$\begingroup\$ @Zacharý Does it? Is
⎕AVUno good? \$\endgroup\$Adám– Adám2017年07月26日 16:03:31 +00:00Commented Jul 26, 2017 at 16:03 -
\$\begingroup\$ Clarification: Why this is 12 bytes and not 4? \$\endgroup\$Adalynn– Adalynn2017年07月26日 16:06:15 +00:00Commented Jul 26, 2017 at 16:06
-
\$\begingroup\$ @Zacharý Ah, simple mistake. \$\endgroup\$Adám– Adám2017年07月26日 16:30:04 +00:00Commented Jul 26, 2017 at 16:30
-
1\$\begingroup\$ Welcome to PPCG! \$\endgroup\$Riker– Riker2017年12月17日 17:43:57 +00:00Commented Dec 17, 2017 at 17:43
-
C++ (gcc), (削除) 120 (削除ここまで) (削除) 133 (削除ここまで) 77 bytes
#import<iostream>
int main(){char c;while(std::cin.get(c))std::cout<<c<<" ";}
Thanks to my father, who showed me a nifty trick for getting the characters directly from the input stream... and in turn almost halfed my byte count!
Old solution below using getline and joining substrings:
#import<iostream>
int i;int main(){std::string s,n;std::getline(std::cin,n);for(;i<n.size();i++){s+=n.substr(i,1)+" ";}std::cout<<s;}
My very first try on golfing. Feel free to give suggestions.
-
\$\begingroup\$ Oh well, that's embarassing. I wrote the same amount of bytes as another answer and that one has got five downvotes. Oops. \$\endgroup\$TheOutZ– TheOutZ2017年12月14日 15:50:27 +00:00Commented Dec 14, 2017 at 15:50
-
2
-
\$\begingroup\$ @tfbninja Fixed. cin isn't particularly fond of strings containing spaces. \$\endgroup\$TheOutZ– TheOutZ2017年12月14日 17:28:34 +00:00Commented Dec 14, 2017 at 17:28
C#, 137 bytes
Func<string,string>f=(a)=>{return string.Concat(a.ToCharArray().SelectMany(x=>(new char[] {' '}),(x, y)=>x.ToString()+y.ToString()));};
doing a console on it gives result : Console.WriteLine(f("arnab bhattacharya")); a r n a b b h a t t a c h a r y a
-
\$\begingroup\$ It's been a while since I've used C#, but I don't believe you need the
Func<string,string>f=part - we allow anonymous functions, so long as they can be captured and called. \$\endgroup\$user45941– user459412016年07月01日 10:18:02 +00:00Commented Jul 1, 2016 at 10:18 -
\$\begingroup\$ @Mego I think he needs to provide datatypes, and he cannot provide them otherwise. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年07月01日 10:28:10 +00:00Commented Jul 1, 2016 at 10:28
-
1\$\begingroup\$ You should read the C# golfing tips thread. :) \$\endgroup\$aloisdg– aloisdg2016年07月06日 18:48:37 +00:00Commented Jul 6, 2016 at 18:48
MATL, 7 bytes
32HY(1e
Explanation
% Implicitly grab input as a string
32 % Number literal (ASCII for ' ')
H % Clipboard H contains 2 by default
Y( % Fill the second "row" with spaces
1e % Force everything onto one row. Due to MATLAB being row-major, this inserts the spaces
% Implicitly display the result
k, 10 bytes
{,/x,'" "}
Explanation
{..} is the lambda syntax
x,'"" takes the first argument x, and applies the join operator , to every character, creating an array of "l " pairs
,/ folds the array with the join operator
APL(NARS), 13 chars, 26 bytes
∊k, ̈' '⍴⍨≢k←⍞
Input a line from standard input, and return a line, test:
∊k, ̈' '⍴⍨≢k←⍞
hello there
h e l l o t h e r e
K (ngn/k), 10 bytes
{,/x,'" "}
(Ignored the stdin constraint. Let me know if I should delete, am new to SE)
EDIT: i made a mistake WRT stdin functionality in k. thanks, @ngn, for the correction:
K (ngn/k), 18 bytes
{1@,/(0:""),'" ";}
k4, 12 bytes
,/(0:0),'" "
which looks like:
,/(0:0),'" "
full-width text
"f u l l - w i d t h t e x t "
-
\$\begingroup\$ Unless ngn/k is completely incapable of taking input any other way, you are not allowed to take input by adding it to your source code, even ignoring this challenge's explicit requirement to use STDIN. \$\endgroup\$The Fifth Marshal– The Fifth Marshal2019年08月19日 16:23:01 +00:00Commented Aug 19, 2019 at 16:23
-
\$\begingroup\$ @pppery there is no stdin functionality within k \$\endgroup\$scrawl– scrawl2019年08月19日 17:23:23 +00:00Commented Aug 19, 2019 at 17:23
-
1\$\begingroup\$
0:""reads from stdin \$\endgroup\$ngn– ngn2019年08月20日 15:13:37 +00:00Commented Aug 20, 2019 at 15:13 -
\$\begingroup\$ @ngn TIL... i will update. thanks! \$\endgroup\$scrawl– scrawl2019年08月20日 15:16:54 +00:00Commented Aug 20, 2019 at 15:16
-
\$\begingroup\$ by the way, it's
0:`in k7 (shakti), i'll add that as an alternative next time i update ngn/k \$\endgroup\$ngn– ngn2019年08月20日 15:20:02 +00:00Commented Aug 20, 2019 at 15:20
W, 4 bytes
"+M
Explanation
M % Foreach the input list:
+ % Join the current item with ...
" % ... A space character
naz, (削除) 50 (削除ここまで) (削除) 42 (削除ここまで) 40 bytes
2x1v1x1f0a0x1x2f1r3x1v1e1o0m8a4m1o2f0x2f
Works for any null-terminated input string.
Saved 8 bytes by condensing the code into 2 functions instead of 3!
Explanation (with 0x instructions removed)
2x1v # Set variable 1 equal to 0
1x1f0a # Function 1
# Add 0 to the register
1x2f1r3x1v1e # Function 2
# Read a byte of input
# Goto function 1 if it equals variable 1
1o0m8a4m1o2f # Otherwise, output it, output a space,
# then call function 2
2f # Call function 2
The only way for a naz program to know when to stop reading its input is to give it a special case to check for; here we use a null byte, since a value of 0 can be stored immediately.
Grok, 13 bytes
:lYW!j
q}W Ih
I just finished my first Esolang and decided to submit a Code-golf answer with it to show it off. It's inspired by Befunge, ><>, and the Vim editor. More information on it is in the GitHub repository.
-
\$\begingroup\$ This looks really cool! I've got a bounty for interesting new languages, and I think this would count as one. If you want I can give this a +100 bounty, or if you want to post another answer that shows off more language features I could award it to that one \$\endgroup\$2021年04月08日 20:49:19 +00:00Commented Apr 8, 2021 at 20:49
-
\$\begingroup\$ @RedwolfPrograms Thanks! I'm glad you like it! I think I'll try and find another challenge so I can show off the features more, especially the register. \$\endgroup\$Aaroneous Miller– Aaroneous Miller2021年04月08日 21:23:56 +00:00Commented Apr 8, 2021 at 21:23
-
\$\begingroup\$ @RedwolfPrograms I think this answer would be a good one for the bounty. \$\endgroup\$Aaroneous Miller– Aaroneous Miller2021年04月12日 16:56:34 +00:00Commented Apr 12, 2021 at 16:56
CLC-INTERCAL, 108 bytes.
DO;1<-#1DO;1SUB#1<-#117DO;2<-#1DOCOMEFROM#9DOWRITEIN;2(1)DO:1<-;2SUB#1DDOCOMEFROM':1~:1'~#1(9)DOREADOUT;2+;1
Copy and paste to try it online!
How it works
DONOTE ;1 has " "
DONOTE ;2 shall accept a character
DO;1<-#1
DO;1SUB#1<-#117
DO;2<-#1
DOCOMEFROM#9
DOWRITEIN;2
DONOTE if EOF, then :1 will be #0
DONOTE otherwise it's at least #65536
(1)DO:1<-;2SUB#1
DONOTE error exit here
D
DONOTE come here if not EOF
DOCOMEFROM':1~:1'~#1
(9)DOREADOUT;2+;1
```
C, 48 bytes
main(c){for(c=8192;read(0,&c,1);write(1,&c,2));}
main(c)declares themainfunction that takes one argumentc. If the data type is not specified, everything is anint. Thereforecis anintvariable.- The
mainroutine consists of oneforstatement,for(...);. The body of theforloop is empty, everything happens inside the control header. c=8192initializecto the value32 * 256.32is the ordinal value of a space character.256shifts the value 8 bits to the left (more significant places).read(0,&c,1)reads1Byte fromSTDIN(0) to the address ofc(&c). This command returns a successful status as long as there is input to read.- Provided the
readis successful,write(1,&c,2)writes2Bytes that are stored at the address ofctoSTDOUT(1).
K (ngn/k), 5 bytes
,/2$'
Runs as a function within the repl.
2$'right-pad each individual character of the input to length 2, i.e. append a space,/flatten the resulting list of strings into a single string and (implicitly) return
If input must be read from STDIN, the following suffices for 9 bytes:
,/2$'*0:`
It is the same as above, but takes a line of input from STDIN via *0:`.
Bespoke, 99 bytes
spacing expands width of my text
it gets enhanced,and it prints better
we see it,and we prefer it
It's too bad spaces delimit words in Bespoke (and take up extra bytes); it would've been really fun to write this in full-width style.
Minkolang 0.15 - 9 bytes
od?.O" "O
Explanation
o Take character from input
d Duplicate top of stack
?. Pop top of stack and jump over the . if truthy, stop otherwise
O Output input char
" "O Output a space
Minkolang's codebox is toroidal, hence there is no need to put an explicit loop in it.
sed, 8 bytes
s/./& /g
When running this from the shell you should quote it of course e.g.
echo Full Width Text | sed 's/./& /g' | od -c
Vitsy, 10 bytes
zl\[O' 'O]
z Grab all string input.
l\[ ] Do the stuff in the brackets length of the stack times.
O O Output as character.
' ' Push literal space.