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

3
\$\begingroup\$

R, 36 bytes

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

Example:

> cat(strsplit(readline(),"")[[1]],"")
Hello R!
H e l l o   R ! 
\$\endgroup\$
1
  • 1
    \$\begingroup\$ You don't need sep=" ", so this can be much shorter: Try it online! \$\endgroup\$
    – Giuseppe
    Commented Mar 9, 2018 at 16:50
2
\$\begingroup\$

Ruby, 24 15 bytes

gsub /./,'\0 '

Requires the -p flag (byte added).

Thanks to xsot for 9 bytes!

\$\endgroup\$
4
  • \$\begingroup\$ Using -p saves 8 bytes \$\endgroup\$
    – xsot
    Commented Mar 23, 2016 at 1:03
  • \$\begingroup\$ @xsot Thanks, I didn't even know that flag existed! \$\endgroup\$
    – Doorknob
    Commented 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
    Commented 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
    Commented Mar 23, 2016 at 1:29
2
\$\begingroup\$

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
\$\endgroup\$
2
  • \$\begingroup\$ Wow, sleek usage of " and wrap-around \$\endgroup\$
    – daniero
    Commented Mar 23, 2016 at 18:21
  • \$\begingroup\$ -1 Byte \$\endgroup\$
    – Jo King
    Commented Dec 19, 2017 at 7:32
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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 .
\$\endgroup\$
4
  • \$\begingroup\$ Nice answer, but i think you mean '/g/ in the test case not '/f'. +1 though. \$\endgroup\$
    – Riker
    Commented Mar 24, 2016 at 2:47
  • \$\begingroup\$ Thank you, 'f' is right next to 'g' on the dvorak keyboard \$\endgroup\$
    – Ben Perlin
    Commented Mar 24, 2016 at 3:37
  • 1
    \$\begingroup\$ My understanding is that a leading space is not permitted. \$\endgroup\$
    – Neil
    Commented Mar 24, 2016 at 10:55
  • \$\begingroup\$ I concur with @Neil. The challenge specifically mentions a trailing space. Therefore the sed command must be something like s/./& /g, which is still 8 Bytes nevertheless. \$\endgroup\$ Commented Mar 15 at 14:54
2
\$\begingroup\$

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=' '

.                          .                             .
.                          .                             .
.                          .                             .
\$\endgroup\$
2
\$\begingroup\$

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 . "
\$\endgroup\$
2
\$\begingroup\$

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+

Try it here!

left_map(input(), " ", add)
\$\endgroup\$
2
\$\begingroup\$

Carrot, 13 bytes, non-competing

#^//./gS" "^ 

(note trailing space in code)

Try it online!

(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

\$\endgroup\$
2
  • \$\begingroup\$ I just accidentally posted this solution without seeing yours. Is there no way to convert to array mode with A by splitting on nothing so Hi becomes [ "H", "i" ]? I though no argument would do it or a space but I was wrong. \$\endgroup\$ Commented 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, A is 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
    Commented Jul 26, 2017 at 16:36
2
\$\begingroup\$

Julia, 31 bytes

print(join(readline(),' ')*" ")

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$
    – Riker
    Commented Dec 17, 2017 at 17:43
  • \$\begingroup\$ 30 bytes \$\endgroup\$
    – MarcMush
    Commented Apr 19, 2021 at 14:48
2
\$\begingroup\$

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;}

Try it Online!

My very first try on golfing. Feel free to give suggestions.

\$\endgroup\$
3
  • \$\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
    Commented Dec 14, 2017 at 15:50
  • 2
    \$\begingroup\$ Welcome to PPCG! I don't know C, but this fails on words with spaces TIO \$\endgroup\$
    – qqq
    Commented Dec 14, 2017 at 15:53
  • \$\begingroup\$ @tfbninja Fixed. cin isn't particularly fond of strings containing spaces. \$\endgroup\$
    – TheOutZ
    Commented Dec 14, 2017 at 17:28
2
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\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
    Commented Jul 1, 2016 at 10:18
  • \$\begingroup\$ @Mego I think he needs to provide datatypes, and he cannot provide them otherwise. \$\endgroup\$ Commented Jul 1, 2016 at 10:28
  • 1
    \$\begingroup\$ You should read the C# golfing tips thread. :) \$\endgroup\$
    – aloisdg
    Commented Jul 6, 2016 at 18:48
2
\$\begingroup\$

MATL, 7 bytes

32HY(1e

Try it Online!

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

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

K (ngn/k), 10 bytes

{,/x,'" "}

Try it online!

(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:""),'" ";}

Try it online!


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 "
\$\endgroup\$
8
  • \$\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\$ Commented Aug 19, 2019 at 16:23
  • \$\begingroup\$ @pppery there is no stdin functionality within k \$\endgroup\$
    – scrawl
    Commented Aug 19, 2019 at 17:23
  • 1
    \$\begingroup\$ 0:"" reads from stdin \$\endgroup\$
    – ngn
    Commented Aug 20, 2019 at 15:13
  • \$\begingroup\$ @ngn TIL... i will update. thanks! \$\endgroup\$
    – scrawl
    Commented 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
    Commented Aug 20, 2019 at 15:20
2
\$\begingroup\$

W, 4 bytes

 "+M

Explanation

   M % Foreach the input list:
  +  % Join the current item with ...
 "   % ... A space character
\$\endgroup\$
2
\$\begingroup\$

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!

Try it online!

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.

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\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\$
    – rydwolf
    Commented 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\$ Commented Apr 8, 2021 at 21:23
  • \$\begingroup\$ @RedwolfPrograms I think this answer would be a good one for the bounty. \$\endgroup\$ Commented Apr 12, 2021 at 16:56
2
\$\begingroup\$

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

C, 48 bytes

main(c){for(c=8192;read(0,&c,1);write(1,&c,2));}

Try it online

  • main(c) declares the main function that takes one argument c. If the data type is not specified, everything is an int. Therefore c is an int variable.
  • The main routine consists of one for statement, for(…);. The body of the for loop is empty, everything happens inside the control header.
  • c=8192 initialize c to the value 32 * 256. 32 is the ordinal value of a space character. 256 shifts the value 8 bits to the left (more significant places).
  • read(0,&c,1) reads 1 Byte from STDIN (0) to the address of c (&c). This command returns a successful status as long as there is input to read.
  • Provided the read is successful, write(1,&c,2) writes 2 Bytes that are stored at the address of c to STDOUT (1).
\$\endgroup\$
1
\$\begingroup\$

Minkolang 0.15 - 9 bytes

od?.O" "O

Try it here!

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.

\$\endgroup\$
1
\$\begingroup\$

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

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.

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Go, 154 120 bytes

package main
import(
."fmt"
."os"
."strings")
func main(){s:=Join(Args[1:], " ")
for _,c:=range s{Print(string(c)," ")}}

Saved a few bytes with command line args.

\$\endgroup\$
1
\$\begingroup\$

LiveScript, 17.

->"#{it/''*' '} "
\$\endgroup\$
1
\$\begingroup\$

Scala, 35 bytes

Console.readLine.map(_+" ")mkString

Example:

scala> Console.readLine.map(_+" ")mkString
res1: String = "H e l l o   S c a l a ! "

PS. A function would be slightly shorter (32 bytes):

(s:String)=>s.map(_+" ")mkString
\$\endgroup\$
1
\$\begingroup\$

Grond, 22 21 chars

a(p().sp('').jn(' '))

Edit: removed semicolon
compiler in js below

String.prototype.reverse = function() {
  return this.split("").reverse().join("");
}
function compile(source){
var wc = source; // wc stands for working copy 
var lastWC;
while (true) {
  lastWC = wc;
  wc = wc.reverse();
  wc = wc.replace(/\(a(?!\w)/, "(trela"); //alert ,a
  wc = wc.replace(/\(f(?!\w)/, "(rof"); // for, f
  wc = wc.replace(/\(w(?!\w)/, "(elihw"); //while,w
  wc = wc.replace(/\(p(?!\w)/, "(tpmorp"); //prompt,p
  wc = wc.replace(/\(vr\./, "(esrever."); //reverse, rv
  wc = wc.replace(/\(tm\./, "(chtam."); // match, mt
  wc = wc.replace(/\(nj\./, "(nioj."); //join, .jn
  wc = wc.replace(/\(pr\./, "(ecalper."); //replace, .rp
  wc = wc.replace(/\(ls\./, "(.ecils"); //slice, sl
  wc = wc.replace(/\(lt\./, "(esaCrewoLot."); //toLowerCase, tl
  wc = wc.replace(/\(ut\./, "(esaCreppUot."); //toUpperCase, tu
    wc = wc.replace(/\(ps\./, "(tilps."); //split, sp
  wc = wc.reverse();
  wc = wc.replace(/\.l(?!\w)/, ".length"); // .length, .l
  if (lastWC === wc)
    break;
}

// quine builtin commented out because it messes things up TODO: Fix it. 
wc = " String.prototype.la=function(h){var x=this.split(''); x[h] = x[h].toLowerCase(); return x.join('');};String.prototype.ca=function(h){var x=this.split(''); x[h] = x[h].toUpperCase(); return x.join('');};String.prototype.reverse=function(){return this.split('').reverse().join('');}; \n var h = ['hello, world', 'Hello, World', 'Hello, World!', 'hello, world!', 'hello world', 'hello world!', 'Hello World', 'Hello World!', 'Hello, world.', 'Hello, World.' ,'hello world.' , 'Hello World.']; /* var q ='" + source + "';*/ " + wc;

return wc;
  }
eval(compile("a(p().sp('').jn(' '));"));//source
Grond on github: https://github.com/epicTCK/Grond

\$\endgroup\$
1
\$\begingroup\$

Ruby, 41 bytes

puts gets.chomp.chars.map{|e|e+" "}.join

chomp eats trailing newlines.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ There is no requirement to output the whole result at once. If you output it piece-by-piece, you can spare the .join call. Even more, if you not need to return the pieces from the code block, then you can spare the .map call too, as .chars also accepts code block. And there is no restriction against adding a space after the trailing newline too, if there is one. gets.chars{|e|$><<e+" "} \$\endgroup\$
    – manatwork
    Commented Mar 23, 2016 at 10:47
1
\$\begingroup\$

Mathematica, 42 bytes

Print@@(#<>" "&)/@Characters@InputString[]

Pretty self-explanatory. InputString takes a line from STDIN, Characters converts it to a list of characters, (#<>" "&)/@ produces a new string with spaces after those characters, and Print prints the result.

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

Nim, 41 bytes

for c in stdin.readAll:stdout.write c&' '

I sure hope there's a better way, but readChar didn't seem to help...

Ideone link

\$\endgroup\$

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.