| Bytes | Lang | Time | Link |
|---|---|---|---|
| 030 | Red | 250317T095007Z | Galen Iv |
| 099 | Bespoke | 250317T054627Z | Josiah W |
| 037 | Tcl | 170112T031937Z | sergiol |
| 250 | jBasher2 | 250121T182542Z | madeforl |
| 009 | Dyalog APL | 160322T205849Z | Ven |
| 005 | K ngn/k | 240315T191042Z | coltim |
| 048 | C | 160323T012134Z | xsot |
| 038 | Swift 5.9 | 240315T122646Z | macOSist |
| 090 | Pascal | 230831T200009Z | Kai Burg |
| 017 | ARBLE | 230903T224039Z | ATaco |
| 039 | Commodore C64 BASIC | 230601T193714Z | Shaun Be |
| 357 | Nibbles | 230601T172638Z | DLosc |
| 043 | Rockstar | 230601T154030Z | Shaggy |
| 030 | Python | 230529T132419Z | The Empt |
| 002 | Thunno 2 J | 230528T185842Z | The Thon |
| 007 | Pushy | 170112T200321Z | FlipTack |
| 004 | Japt | 170303T192203Z | Oliver |
| 108 | CLCINTERCAL | 210925T003526Z | user1004 |
| 019 | Javascript | 170604T223935Z | Victor |
| 029 | Factor + sequences.interleaved | 210923T194903Z | chunes |
| 006 | Silicon | 160701T100843Z | m654 |
| 002 | Vyxal Ṫ | 210426T152906Z | Aaroneou |
| 013 | Grok | 210408T204404Z | Aaroneou |
| 016 | Zsh | 210214T160134Z | pxeger |
| 010 | BRASCA | 210212T103137Z | SjoerdPe |
| 040 | naz | 200102T072524Z | sporebal |
| 003 | 05AB1E | 210202T184313Z | Makonede |
| 008 | PowerShell | 200102T013754Z | GMills |
| 044 | C# Visual C# Interactive Compiler | 200102T082424Z | Jirka Pi |
| 003 | Keg | 191228T213136Z | lyxal |
| 004 | W | 191228T145648Z | user8505 |
| 006 | Befunge98 PyFunge | 190909T151109Z | david |
| 021 | Zsh | 190909T104507Z | GammaFun |
| 010 | K ngn/k | 190819T162047Z | scrawl |
| 105 | C# | 190819T191408Z | canttalk |
| 002 | Jelly | 160322T175356Z | Adnan |
| 043 | Elixir | 160322T211410Z | Ven |
| 026 | APLNARS | 190213T092111Z | user5898 |
| 002 | Japt P | 190212T171209Z | Shaggy |
| 024 | PowerShell | 190212T135624Z | mazzy |
| 007 | Gol><> | 190212T001452Z | KrystosT |
| 014 | Perl 6 | 190212T005354Z | Jo King |
| 044 | C# Visual C# Interactive Compiler | 190211T233542Z | dana |
| 008 | Ahead | 190211T062620Z | snail_ |
| 023 | Brainfuck | 180127T091919Z | Dust |
| 009 | SMBF | 160322T200739Z | mbomb007 |
| 036 | R | 160322T203931Z | lambrusc |
| 010 | k | 180309T125059Z | ulucs |
| 003 | Canvas | 180303T191910Z | hakr14 |
| 002 | Stax | 180303T172853Z | Khuldrae |
| 039 | SmileBASIC | 180303T170151Z | 12Me21 |
| 007 | MATL | 160416T180206Z | Suever |
| 040 | Common Lisp | 160323T221310Z | Soupy |
| nan | Python 3 | 180126T161731Z | Mercury |
| 034 | Standard ML Mlton | 180126T150446Z | Laikoni |
| 019 | Excel VBA | 170703T184830Z | Taylor R |
| 045 | Swift | 171218T190808Z | Endenite |
| 071 | SNOBOL4 CSNOBOL4 | 171218T184349Z | Giuseppe |
| 049 | Rust | 171218T183205Z | Håv |
| 018 | Python 3.5 | 160322T182856Z | vaultah |
| 028 | Python 3 | 160322T224348Z | Raffi |
| 062 | Python 2.7 | 160323T125247Z | MrPublic |
| 046 | C | 160322T194947Z | SBI |
| 039 | Python 3 | 160322T192843Z | Yytsi |
| nan | Java | 160322T175510Z | CAD97 |
| 050 | C | 160418T022131Z | homersim |
| 137 | C# | 160701T083115Z | Arnab Bh |
| 035 | C# | 160706T185608Z | aloisdg |
| 049 | C | 170112T043525Z | Abel Tom |
| 024 | Python 2 | 160701T083348Z | Erik the |
| 052 | C# | 170331T190402Z | adrianmp |
| 077 | C++ gcc | 171214T154759Z | TheOutZ |
| 031 | Julia | 171217T172443Z | LukeS |
| 008 | MY | 170726T155938Z | Adalynn |
| 004 | APL Dyalog | 170726T145053Z | Adá |
| 363 | Taxi | 170726T161535Z | Engineer |
| 037 | AHK | 170726T160902Z | Engineer |
| 046 | BrainFlak | 170703T183521Z | DJMcMayh |
| 010 | Vim | 170604T161139Z | BlackCap |
| 012 | q/kdb+ | 170604T175300Z | mkst |
| 013 | Carrot | 170303T200635Z | user4180 |
| 044 | SmileBASIC 3 | 170304T052134Z | snail_ |
| 057 | Lua | 170303T201704Z | Josh |
| 016 | Threead | 170112T060351Z | ATaco |
| 009 | Cubix | 170112T221103Z | FlipTack |
| 049 | OIL | 170112T104829Z | L3viatha |
| 031 | PHP | 170112T063608Z | Titus |
| 044 | TI84 BASIC | 170112T063022Z | Jakob |
| 010 | Cubix | 160323T195506Z | MickyT |
| 087 | Batch | 160322T221037Z | Neil |
| 046 | Swift 2.2 | 160706T190541Z | JAL |
| 031 | Lua | 160323T082450Z | Katenkyo |
| 022 | brainfuck | 160322T195231Z | mbomb007 |
| 044 | Tcl | 160704T074733Z | Byeonggo |
| 005 | Pyke | 160322T181625Z | Blue |
| 005 | APL | 160701T104305Z | Moris Zu |
| 026 | 0815 | 160701T104237Z | Erik the |
| 005 | Pyth | 160701T084117Z | Arfie |
| 041 | Hoon | 160418T030248Z | RenderSe |
| 011 | Ouroboros | 160417T220647Z | DLosc |
| 005 | Pip | 160417T210810Z | DLosc |
| 025 | MATLAB | 160416T182031Z | Suever |
| 018 | Octave | 160416T181327Z | Suever |
| 007 | MATL | 160322T175324Z | Luis Men |
| 020 | beeswax | 160329T132136Z | M L |
| 005 | Gema | 160322T180421Z | manatwor |
| 010 | Hexagony | 160322T184234Z | Adnan |
| 018 | Befunge93 | 160323T105636Z | Jevado |
| 051 | Matlab/Octave | 160324T035626Z | Ben Perl |
| 008 | Sed | 160324T021140Z | Ben Perl |
| 005 | Japt | 160323T031515Z | Mama Fun |
| 011 | Labyrinth | 160323T091627Z | Sp3000 |
| 011 | Prelude | 160323T184811Z | Martin E |
| 010 | Labyrinth | 160323T175944Z | Martin E |
| 038 | WhoScript | 160323T023347Z | MCS-Kaij |
| 032 | PowerShell | 160323T165723Z | Matt |
| 008 | J | 160323T165205Z | Conor O& |
| 012 | Befunge93 | 160323T162816Z | Sp3000 |
| 057 | 𝔼𝕊𝕄𝕚𝕟 | 160323T030553Z | Mama Fun |
| 021 | Befunge98 | 160323T151737Z | Luke Mar |
| 004 | Pyth | 160322T174623Z | Maltysen |
| 039 | PHP | 160323T111847Z | ʰᵈˑ |
| 035 | Javascript | 160323T094117Z | Qwertiy |
| nan | Perl 5 | 160322T210407Z | Ven |
| 006 | O 1.2 | 160323T083647Z | manatwor |
| 003 | Convex | 160322T182605Z | GamrCorp |
| 034 | Clojure | 160323T031013Z | MattPutn |
| 010 | RETURN | 160323T025319Z | Mama Fun |
| 007 | Jolf | 160323T025347Z | Conor O& |
| 005 | Retina | 160322T175022Z | Digital |
| 015 | Reng v.1.2 | 160323T024514Z | Conor O& |
| 010 | ><> | 160323T014824Z | Luis Men |
| 041 | Nim | 160323T014044Z | Sp3000 |
| 020 | JavaScript | 160322T182254Z | Generic |
| 015 | Ruby | 160322T222504Z | Doorknob |
| 042 | Mathematica | 160322T210245Z | LegionMa |
| 041 | Ruby | 160322T200235Z | jose_cas |
| 021 | Grond | 160322T234135Z | Bald Ban |
| 035 | Scala | 160322T204615Z | lambrusc |
| 017 | LiveScript | 160322T205115Z | Ven |
| 120 | Go | 160322T201724Z | EMBLEM |
| 007 | Awk | 160322T190810Z | manatwor |
| 010 | Vitsy | 160322T201849Z | Addison |
| 092 | Java | 160322T200251Z | shooqie |
| 006 | GolfScript | 160322T185914Z | Dennis |
| 008 | sed | 160322T184313Z | Neil |
| 004 | CJam | 160322T183244Z | Luis Men |
| 004 | 05AB1E | 160322T180142Z | a spaghe |
| 009 | Minkolang 0.15 | 160322T180553Z | El'e |
| 011 | Haskell | 160322T180247Z | nimi |
| 007 | Seriously | 160322T180107Z | user4594 |
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.
Tcl, 37 bytes
puts [join [split [gets stdin] ""]]\
puts [regsub -all (.) [gets stdin] \\1\ ]
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
Dyalog APL, 11 9 bytes
,/,∘' '¨
Train that each-adds a space, then joins
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:`.
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).
Swift 5.9, 38 bytes
let f={($0+"").map{" \($0)"}.joined()}
Pascal, 90 bytes
This is a full program suitable for a processor supporting “Standard Pascal” and/or “Extended Pascal” as defined by ISO standards 7185 and 10206 respectively.
As per specification it takes a line (not many lines).
Note, calling EOLn(input) causes an error if EOF(input) is true prior invocation of EOLn.
Hence it must be guaranteed that input contains at least an end‑of‑line marker.
program p(input,output);begin while not EOLn do begin write(input↑,' ');get(input)end end.
We can add −10 bytes if it is guaranteed that input is a non‑empty line:
program p(input,output);begin repeat write(input↑,' ');get(input)until EOLn end.
Commodore C64 BASIC, 39 Tokenised BASIC bytes, 42 PETSCII characters with keyword abbreviations
0INPUTA$:FORI=1TOLEN(A$):?MID$(A$,I,1)" ";:NEXT
On running this listing, the interpreter will expect an input of strings which when the return key is pressed, will store the text entered into the variable A$. It will then iterate over each position of the string to its length and PRINT it, proceeded by a white space, and then will continue at the next cursor position until the final character of the string is printed (this will be followed by a space too).
Some notes: A Commodore C64 screen is 40 characters wide by default, and the maximum number of characters that may be stored in a string is 255, however, when using INPUT the interpreter will only accept a total entry of 77 characters without some trickery (80 characters if you delete the ? prompt, enter 80 characters and then cursor up two lines and press the RETURN key).
See screenshot for this in action.
Nibbles, 3.5 bytes (7 nibbles)
+.@:$" "
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
Rockstar, 43 bytes
listen to S
cut S
join S with " "
say S+" "
Try it (Code will need to be pasted in)
Thunno 2 J, 2 bytes
ðṖ
Port of Dennis's Jelly answer: cartesian product with space. J flag joins the list.
Pushy, 7 bytes
32DL:{'
Works like so:
\ Implicit: Input is on stack as charcodes
32D \ Set the printing delimiter to a space
L: \ Input length times do:
{ \ Cyclically shift the stack left
' \ Print the last character (includes trailing space)
Alternatively, for the same byte count, one could have:
L:{32;"
L: ; \ Length times do:
{ \ Shift string left
32 \ Insert char 32 (a space)
" \ Afterwards, print the whole string
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
```
Javascript, 19 bytes
s=>[...s,,].join` `
Factor + sequences.interleaved, 29 bytes
readln 32 <interleaved> print
Modern versions of Factor (i.e. not TIO) allow most sequences to be printed as strings. So have a screenshot of running this in the listener:
Silicon, 6 bytes
iSæ%æ+
Explanation:
iSæ%æ+
i Input
S Split the input
æ Push a space
% Join at spaces
æ+ Append a space to the end of the string
Implicit output
7 bytes
iSæ²jæ+
Vyxal Ṫ, 3 2 bytes
Ṅð
Explanation:
# Implicit input
Ṅ # Insert ' ' between each character
ð # Push ' '
# 'Ṫ' flag - sum entire stack and print
If the final space wasn't necessary:
Vyxal S, 0 bytes
Explanation:
# Implicit input
# 'S' flag - Print top of stack joined by spaces
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.
BRASCA, 10 bytes
![aEmmA{]x
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
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.
05AB1E, 3 bytes
ðâJ
ðâJ # full program
J # join...
â # cartesian product of...
# implicit input...
â # and...
ð # " "
# implicit output
PowerShell, 17 8 bytes
-9 bytes thanks to @mazzy!
"$args "
There are already a couple of PowerShell answers to this question, but I thought I'd throw mine into the mix. It takes splatter input from a command line argument. It also assumes that $ofs is equal to one space, which it is by default.
C# (Visual C# Interactive Compiler), 44 bytes
Version reading an argument
Write(string.Join(" ",Args[0].ToList())+" ")
47 bytes
Version reading standard input
Write(string.Join(" ",ReadLine().ToList())+" ")
Keg, -rs, 3 bytes
( '
Shifts the input putting a space after each character, reverses the stack via the -rs flag and then implicitly outputs the stack.
W, 4 bytes
"+M
Explanation
M % Foreach the input list:
+ % Join the current item with ...
" % ... A space character
Befunge-98 (PyFunge), 6 bytes
"#@~,,
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,
Zsh, 21 bytes
echo ${(s::)$(<&0)}\
$(capture), ${(s::)plit}, echo. The last "\ " is needed for the trailing space.
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 "
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
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.
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).
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
Gol><>, 7 bytes
iEH}` }
Courtesy of JoKing, who golfed this to the max!!! JoKing combined the loops into one simple loop, also avoided the mistake I made, I added 2 spaces rather than one.
Slightly newer of My original golfed, 23 bytes
Ti:0)?t~l&T` }}&M:&?trH
Old version, 28 bytes
Ti:0)?t~l&T" "}}}&M:&0)?trH
This can probably be golfed futher, but code breakdown below!
Ti:0)?t~l&T" "}}}&M:&0)?trH
Ti:0)?t~ //gets every char from input, and pushes them to the stack
T" "}}} //push 2 spaces after every char, push to the bottom of the stack for later
l&T &M:&0)?t //push original length and store, every loop decrement and if it is greater than zero, repeat
rH//reverse stack and output the whole stack as characters
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
C# (Visual C# Interactive Compiler), 44 bytes
for(int c;-1<(c=Read());Write((char)c+" "));
Not the first C# submission :) But it follows the challenge to the letter in terms of using STDIN and STDOUT.
Brainfuck, 23 24 25 Bytes
1 Byte thanks to ovs
-[-[-<]>>+<]>-<+[,.>.<]
Try it online!
This code makes use of most interpreters wrapping to 255 if the number is negative.
Previous solution:
++++[>++++++++<-]+[,.>.<]
Explanation:
++++[>++++++++<-] |Leaves the second cell with the number 32, the ASCII Code for a space.
+[,.>.<] |Simple loop, gets the input, outputs it and adds a space.
Suggestions are welcome.
SMBF, 9 bytes
Note the trailing space. Uses the space in the code rather than creating a 32 in a cell.
,[.<.>,]
The tryitonline.net interpreter appears to have a bug and loop indefinitely with this, so it only works in my Python interpreter. Changing the SMBF source code (currently on line 171) inside the Python code is required.
R, 36 bytes
cat(strsplit(readline(),"")[[1]],"")
Example:
> cat(strsplit(readline(),"")[[1]],"")
Hello R!
H e l l o R !
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
Canvas, 4 3 bytes
]∑
Explanation:
Push input to stack (implicit)
For each character in the input: (implicit)
Push the character to the stack (implicit)
Push " " to the stack
] Collapse results from loop into an array
∑ Join the array into a single string
Print the ToS (implicit)
-1 byte thanks to dzaima!
Stax, 2 bytes
Ties Jelly!
0\
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.
SmileBASIC, 39 bytes
LINPUT A$WHILE""<A$?SHIFT(A$);" ";
WEND
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
Common Lisp, 40 bytes
(map()(lambda(x)(format t"~C "x))(read))
I was very surprised that format couldn't do this by itself: it can only iterate over lists, not strings.
Python 3, 95 93 92 80 32 26 30 bytes
Saved a byte thanks to @caird coinheringaahing
Saved bunch of bytes from @DJMcMayhem + My idea
print(' '.join(input())+' ')
Takes input, splits it, then prints a join with spaces
This is my first time golfing.
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 *)
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 " "
SNOBOL4 (CSNOBOL4), 71 bytes
I =INPUT
S I LEN(1) . X REM . I :F(O)
O =O X ' ' :(S)
O OUTPUT =O
END
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.
Python 3.5, 18 bytes
print(*input(),'')
This works because print's default separator is single space.
Python 3, 31 28
print(' '.join(input())+' ')
I know i'm late on this one, and definitely not a winner, but thought i'd try it out.
Edit: Switched to python 3. Thanks to CatsAreFluffy for saving 3 bytes!
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))]))
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
Python 3, 39 bytes
print("".join([x+" "for x in input()]))
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 ")
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.
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
C#, 35 bytes
s=>string.Join(" ",s.ToList())+" ";
C# lambda where the input and the output are string. You can try it on .NetFiddle.
C 55, 49 bytes
g(){c;while((c=getchar())!='\n')printf("%c ",c);}
Ungolfed version:
void g()
{
char c;
while((c=getchar())!='\n')
printf("%c ", c);
}
Python 2, 27 25 24 bytes
lambda x:' '.join(x)+' '
Shorter than Raffi's answer...
-1 thanks to 60919 (FlipTack).
C#, 52 bytes
Manual, straightforward approach, without using Linq.
s=>{var r="";foreach(var c in s)r+=c+" ";return r;};
Anonymous method which gets every character from the string and adds a space after each one.
Full program:
using System;
namespace FullWidthText
{
class Program
{
static void Main(string[] args)
{
Func<string, string> f =
s =>
{
var r = "";
foreach (var c in s)
r += c + " ";
return r;
};
Console.WriteLine(f("Full width text is text that has a space after every character, including the last one."));
}
}
}
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.
MY, 8 bytes (noncompeting)
⍞ηυ←2Ġ'←
Explanation:
1E/⍞- receive a line of input from STDIN57/η- split into individual characters58/υ- joined by spaces26/←- print to STDOUT without a newline02/2- push 2 to the stack25/Ġ- 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 υ.
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)
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]
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.
AHK, 37 bytes
Loop,Parse,1
Send,%A_LoopField%{VK20}
The variable 1 is the first passed argument. {VK20} is a space.
Brain-Flak, 46 bytes
{({}<>)<>}<>{({}<>)((((()()()()){}){}){})<>}<>
Explanation:
#Reverse the whole stack
{({}<>)<>}<>
#Reverse the whole stack,
{({}<>)
#Pushing 32 between each character
((((()()()()){}){}){})<>}<>
Vim, 12 10 keystrokes
:s/./& /g<CR>
1 byte longer:
qqa <Esc>l@qq@q
-2 bytes thanks to @KritixiLithos
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 ! "
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
SmileBASIC 3, 44 bytes
INPUT A$FOR I=0TO LEN(A$)-1?A$[I]+" ";
NEXT
This doesn't leave a new line after the output, so from direct you might get
?HELLO
H E L L O OK
but hopefully it's not an issue.
Lua, 57 bytes
t=""io.read():gsub(".",function(c)t=t..c.." "end)print(t)
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.
Cubix, 9 bytes
@./.i?>So
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.
OIL, 52 49 bytes noncompeting
Note: The second line contains a space character.
5
12
0
23
10
24
3
7
10
4
24
4
1
8
11
1
11
6
6
5
I explode the input string, then print each character and then a space.
PHP, 31 bytes
<?=chunk_split($argv[1],1," ");
takes input from command line argument.
TI-84 BASIC, 44 bytes
Pretty straightforward approach:
Input Str1
sub(Str1,1,1
For(A,2,length(Str1
Ans+" "+sub(Str1,A,1
End
Ans+"
The only size optimizations I could come up with were:
- leaving off closing quotes and parentheses at the end of lines
- using
Ansinstead of a string variable (theAnstoken is 1 byte,StrNare 2, and assignment toAnsis implicit) - printing the result by placing it on the last line of the program (no
Dispcommand needed)
This program wouldn't work correctly for an empty input string, since it unconditionally stores the first character of Str1 in Ans. (This is necessary because concatenation with an empty string raises an error!) Fortunately, the Input command doesn't accept an empty string in the first place.
The size calculation was informed by TI-Basic Developer's token size charts.
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.
Batch, 87 bytes
@set/pt=&set w=
:l
@if not "%t%"=="" set w=%w%%t:~,1% &set t=%t:~1%&goto l
@echo(%w%
Conveniently taking input from STDIN is the same length as taking it from program arguments (set t=%*). The space between the % and & on the third line is significant, of course. The ( after the echo simply prevents it from erroring out if the input is empty.
Swift 2.2, 48 46 bytes
for c in i.characters{print(c,terminator:" ")}
Hey, at least it's shorter than Java... Saved 2 chars by using a for in loop instead of a forEach closure.
Lua, 31 Bytes
Saved 1 byte thanks to @LeakyNun
A simple chained substitution, replace each character by itself and a space.
s=(...):gsub(".","%1 ")print(s)
An other solution with the same byte count:
print((...):gsub(".","%1 "),'')
brainfuck, 24 22 bytes
Simple example using the shortest known 32 for the space character(s).
,[.>>-[-[-<]>>+<]>-.,]
Tcl, 44 bytes
puts [regsub -all {(.)} [gets stdin] {\1 }]
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)
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.
0815, 26 bytes
<:20:~>}: :!~$#:
:{~$>^: :
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 . "
Ouroboros, 11 bytes
i.0<5*(o32o
Ouroboros is an esolang in which every line of code represents a snake eating its tail. It draws a fair amount of inspiration from 2D languages like Befunge and ><>.
The i command reads a character, or -1 for EOF. We duplicate this, check if it's less than 0, and multiply the resulting 1 (true) or 0 (false) by 5.
- If we have reached EOF, the top of the stack is now
5. The(command tells the snake to eat that many characters of its tail. This results in swallowing the execution pointer (currently on(, the fifth-last character), which terminates the program. - Otherwise,
0characters are eaten, and execution continues. We have a copy of the input ASCII code on the stack, which we output viao; then output a space (ASCII 32) and loop back to the beginning.
Try it out
// Define Stack class
function Stack() {
this.stack = [];
this.length = 0;
}
Stack.prototype.push = function(item) {
this.stack.push(item);
this.length++;
}
Stack.prototype.pop = function() {
var result = 0;
if (this.length > 0) {
result = this.stack.pop();
this.length--;
}
return result;
}
Stack.prototype.top = function() {
var result = 0;
if (this.length > 0) {
result = this.stack[this.length - 1];
}
return result;
}
Stack.prototype.toString = function() {
return "" + this.stack;
}
// Define Snake class
function Snake(code) {
this.code = code;
this.length = this.code.length;
this.ip = 0;
this.ownStack = new Stack();
this.currStack = this.ownStack;
this.alive = true;
this.wait = 0;
this.partialString = this.partialNumber = null;
}
Snake.prototype.step = function() {
if (!this.alive) {
return null;
}
if (this.wait > 0) {
this.wait--;
return null;
}
var instruction = this.code.charAt(this.ip);
var output = null;
console.log("Executing instruction " + instruction);
if (this.partialString !== null) {
// We're in the middle of a double-quoted string
if (instruction == '"') {
// Close the string and push its character codes in reverse order
for (var i = this.partialString.length - 1; i >= 0; i--) {
this.currStack.push(this.partialString.charCodeAt(i));
}
this.partialString = null;
} else {
this.partialString += instruction;
}
} else if (instruction == '"') {
this.partialString = "";
} else if ("0" <= instruction && instruction <= "9") {
if (this.partialNumber !== null) {
this.partialNumber = this.partialNumber + instruction; // NB: concatenation!
} else {
this.partialNumber = instruction;
}
next = this.code.charAt((this.ip + 1) % this.length);
if (next < "0" || "9" < next) {
// Next instruction is non-numeric, so end number and push it
this.currStack.push(+this.partialNumber);
this.partialNumber = null;
}
} else if ("a" <= instruction && instruction <= "f") {
// a-f push numbers 10 through 15
var value = instruction.charCodeAt(0) - 87;
this.currStack.push(value);
} else if (instruction == "$") {
// Toggle the current stack
if (this.currStack === this.ownStack) {
this.currStack = this.program.sharedStack;
} else {
this.currStack = this.ownStack;
}
} else if (instruction == "s") {
this.currStack = this.ownStack;
} else if (instruction == "S") {
this.currStack = this.program.sharedStack;
} else if (instruction == "l") {
this.currStack.push(this.ownStack.length);
} else if (instruction == "L") {
this.currStack.push(this.program.sharedStack.length);
} else if (instruction == ".") {
var item = this.currStack.pop();
this.currStack.push(item);
this.currStack.push(item);
} else if (instruction == "m") {
var item = this.ownStack.pop();
this.program.sharedStack.push(item);
} else if (instruction == "M") {
var item = this.program.sharedStack.pop();
this.ownStack.push(item);
} else if (instruction == "y") {
var item = this.ownStack.top();
this.program.sharedStack.push(item);
} else if (instruction == "Y") {
var item = this.program.sharedStack.top();
this.ownStack.push(item);
} else if (instruction == "\\") {
var top = this.currStack.pop();
var next = this.currStack.pop()
this.currStack.push(top);
this.currStack.push(next);
} else if (instruction == "@") {
var c = this.currStack.pop();
var b = this.currStack.pop();
var a = this.currStack.pop();
this.currStack.push(c);
this.currStack.push(a);
this.currStack.push(b);
} else if (instruction == ";") {
this.currStack.pop();
} else if (instruction == "+") {
var b = this.currStack.pop();
var a = this.currStack.pop();
this.currStack.push(a + b);
} else if (instruction == "-") {
var b = this.currStack.pop();
var a = this.currStack.pop();
this.currStack.push(a - b);
} else if (instruction == "*") {
var b = this.currStack.pop();
var a = this.currStack.pop();
this.currStack.push(a * b);
} else if (instruction == "/") {
var b = this.currStack.pop();
var a = this.currStack.pop();
this.currStack.push(a / b);
} else if (instruction == "%") {
var b = this.currStack.pop();
var a = this.currStack.pop();
this.currStack.push(a % b);
} else if (instruction == "_") {
this.currStack.push(-this.currStack.pop());
} else if (instruction == "I") {
var value = this.currStack.pop();
if (value < 0) {
this.currStack.push(Math.ceil(value));
} else {
this.currStack.push(Math.floor(value));
}
} else if (instruction == ">") {
var b = this.currStack.pop();
var a = this.currStack.pop();
this.currStack.push(+(a > b));
} else if (instruction == "<") {
var b = this.currStack.pop();
var a = this.currStack.pop();
this.currStack.push(+(a < b));
} else if (instruction == "=") {
var b = this.currStack.pop();
var a = this.currStack.pop();
this.currStack.push(+(a == b));
} else if (instruction == "!") {
this.currStack.push(+ !this.currStack.pop());
} else if (instruction == "?") {
this.currStack.push(Math.random());
} else if (instruction == "n") {
output = "" + this.currStack.pop();
} else if (instruction == "o") {
output = String.fromCharCode(this.currStack.pop());
} else if (instruction == "r") {
var input = this.program.io.getNumber();
this.currStack.push(input);
} else if (instruction == "i") {
var input = this.program.io.getChar();
this.currStack.push(input);
} else if (instruction == "(") {
this.length -= Math.floor(this.currStack.pop());
this.length = Math.max(this.length, 0);
} else if (instruction == ")") {
this.length += Math.floor(this.currStack.pop());
this.length = Math.min(this.length, this.code.length);
} else if (instruction == "w") {
this.wait = this.currStack.pop();
}
// Any unrecognized character is a no-op
if (this.ip >= this.length) {
// We've swallowed the IP, so this snake dies
this.alive = false;
this.program.snakesLiving--;
} else {
// Increment IP and loop if appropriate
this.ip = (this.ip + 1) % this.length;
}
return output;
}
Snake.prototype.getHighlightedCode = function() {
var result = "";
for (var i = 0; i < this.code.length; i++) {
if (i == this.length) {
result += '<span class="swallowedCode">';
}
if (i == this.ip) {
if (this.wait > 0) {
result += '<span class="nextActiveToken">';
} else {
result += '<span class="activeToken">';
}
result += escapeEntities(this.code.charAt(i)) + '</span>';
} else {
result += escapeEntities(this.code.charAt(i));
}
}
if (this.length < this.code.length) {
result += '</span>';
}
return result;
}
// Define Program class
function Program(source, speed, io) {
this.sharedStack = new Stack();
this.snakes = source.split(/\r?\n/).map(function(snakeCode) {
var snake = new Snake(snakeCode);
snake.program = this;
snake.sharedStack = this.sharedStack;
return snake;
}.bind(this));
this.snakesLiving = this.snakes.length;
this.io = io;
this.speed = speed || 10;
this.halting = false;
}
Program.prototype.run = function() {
this.step();
if (this.snakesLiving) {
this.timeout = window.setTimeout(this.run.bind(this), 1000 / this.speed);
}
}
Program.prototype.step = function() {
for (var s = 0; s < this.snakes.length; s++) {
var output = this.snakes[s].step();
if (output) {
this.io.print(output);
}
}
this.io.displaySource(this.snakes.map(function (snake) {
return snake.getHighlightedCode();
}).join("<br>"));
}
Program.prototype.halt = function() {
window.clearTimeout(this.timeout);
}
var ioFunctions = {
print: function (item) {
var stdout = document.getElementById('stdout');
stdout.value += "" + item;
},
getChar: function () {
if (inputData) {
var inputChar = inputData[0];
inputData = inputData.slice(1);
result = inputChar.charCodeAt(0);
} else {
result = -1;
}
var stdinDisplay = document.getElementById('stdin-display');
stdinDisplay.innerHTML = escapeEntities(inputData);
return result;
},
getNumber: function () {
while (inputData && (inputData[0] < "0" || "9" < inputData[0])) {
inputData = inputData.slice(1);
}
if (inputData) {
var inputNumber = inputData.match(/\d+/)[0];
inputData = inputData.slice(inputNumber.length);
result = +inputNumber;
} else {
result = -1;
}
var stdinDisplay = document.getElementById('stdin-display');
stdinDisplay.innerHTML = escapeEntities(inputData);
return result;
},
displaySource: function (formattedCode) {
var sourceDisplay = document.getElementById('source-display');
sourceDisplay.innerHTML = formattedCode;
}
};
var program = null;
var inputData = null;
function showEditor() {
var source = document.getElementById('source'),
sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
stdin = document.getElementById('stdin'),
stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
source.style.display = "block";
stdin.style.display = "block";
sourceDisplayWrapper.style.display = "none";
stdinDisplayWrapper.style.display = "none";
source.focus();
}
function hideEditor() {
var source = document.getElementById('source'),
sourceDisplay = document.getElementById('source-display'),
sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
stdin = document.getElementById('stdin'),
stdinDisplay = document.getElementById('stdin-display'),
stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
source.style.display = "none";
stdin.style.display = "none";
sourceDisplayWrapper.style.display = "block";
stdinDisplayWrapper.style.display = "block";
var sourceHeight = getComputedStyle(source).height,
stdinHeight = getComputedStyle(stdin).height;
sourceDisplayWrapper.style.minHeight = sourceHeight;
sourceDisplayWrapper.style.maxHeight = sourceHeight;
stdinDisplayWrapper.style.minHeight = stdinHeight;
stdinDisplayWrapper.style.maxHeight = stdinHeight;
sourceDisplay.textContent = source.value;
stdinDisplay.textContent = stdin.value;
}
function escapeEntities(input) {
return input.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
function resetProgram() {
var stdout = document.getElementById('stdout');
stdout.value = null;
if (program !== null) {
program.halt();
}
program = null;
inputData = null;
showEditor();
}
function initProgram() {
var source = document.getElementById('source'),
stepsPerSecond = document.getElementById('steps-per-second'),
stdin = document.getElementById('stdin');
program = new Program(source.value, +stepsPerSecond.innerHTML, ioFunctions);
hideEditor();
inputData = stdin.value;
}
function runBtnClick() {
if (program === null || program.snakesLiving == 0) {
resetProgram();
initProgram();
} else {
program.halt();
var stepsPerSecond = document.getElementById('steps-per-second');
program.speed = +stepsPerSecond.innerHTML;
}
program.run();
}
function stepBtnClick() {
if (program === null) {
initProgram();
} else {
program.halt();
}
program.step();
}
function sourceDisplayClick() {
resetProgram();
}
.container {
width: 100%;
}
.so-box {
font-family:'Helvetica Neue', Arial, sans-serif;
font-weight: bold;
color: #fff;
text-align: center;
padding: .3em .7em;
font-size: 1em;
line-height: 1.1;
border: 1px solid #c47b07;
-webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
background: #f88912;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
}
.control {
display: inline-block;
border-radius: 6px;
float: left;
margin-right: 25px;
cursor: pointer;
}
.option {
padding: 10px 20px;
margin-right: 25px;
float: left;
}
h1 {
text-align: center;
font-family: Georgia, 'Times New Roman', serif;
}
a {
text-decoration: none;
}
input, textarea {
box-sizing: border-box;
}
textarea {
display: block;
white-space: pre;
overflow: auto;
height: 50px;
width: 100%;
max-width: 100%;
min-height: 25px;
}
span[contenteditable] {
padding: 2px 6px;
background: #cc7801;
color: #fff;
}
#stdout-container, #stdin-container {
height: auto;
padding: 6px 0;
}
#reset {
float: right;
}
#source-display-wrapper , #stdin-display-wrapper{
display: none;
width: 100%;
height: 100%;
overflow: auto;
border: 1px solid black;
box-sizing: border-box;
}
#source-display , #stdin-display{
font-family: monospace;
white-space: pre;
padding: 2px;
}
.activeToken {
background: #f93;
}
.nextActiveToken {
background: #bbb;
}
.swallowedCode{
color: #999;
}
.clearfix:after {
content:".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {
display: inline-block;
}
* html .clearfix {
height: 1%;
}
.clearfix {
display: block;
}
<!--
Designed and written 2015 by D. Loscutoff
Much of the HTML and CSS was taken from this Befunge interpreter by Ingo Bürk: http://codegolf.stackexchange.com/a/40331/16766
-->
<div class="container">
<textarea id="source" placeholder="Enter your program here" wrap="off">i.0<5*(o32o</textarea>
<div id="source-display-wrapper" onclick="sourceDisplayClick()"><div id="source-display"></div></div></div><div id="stdin-container" class="container">
<textarea id="stdin" placeholder="Input" wrap="off">Input text...</textarea>
<div id="stdin-display-wrapper" onclick="stdinDisplayClick()"><div id="stdin-display"></div></div></div><div id="controls-container" class="container clearfix"><input type="button" id="run" class="control so-box" value="Run" onclick="runBtnClick()" /><input type="button" id="pause" class="control so-box" value="Pause" onclick="program.halt()" /><input type="button" id="step" class="control so-box" value="Step" onclick="stepBtnClick()" /><input type="button" id="reset" class="control so-box" value="Reset" onclick="resetProgram()" /></div><div id="stdout-container" class="container"><textarea id="stdout" placeholder="Output" wrap="off" readonly></textarea></div><div id="options-container" class="container"><div class="option so-box">Steps per Second:
<span id="steps-per-second" contenteditable>20</span></div></div>
Pip, 5 bytes
_.sMq
The special variable q reads a line of stdin. We Map to it the lambda function _.s, which concatenates a space to each character. By default, the resulting list is concatenated and autoprinted.
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.
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.
MATL, 7 bytes
tnZ"v1e
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
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=' '
. . .
. . .
. . .
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 .
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 / * ;
@ . > . .
. . . .
. . .
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:
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:
This basically goes to the @ command, which terminates the program.
Using Timwi's amazing HexagonyColorer for making the diagrams.
Befunge-93, 18 bytes
>~:1`#v_@
^," ",<
Matlab/Octave, 51 bytes
s=s(.5:.5:length(s))
s(1:2:length(s))=' '
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 .
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.
Prelude, 11 bytes
?(!8^+^+!?)
This needs a spec-compliant interpreter which reads and writes character codes (instead of integers).
The program is fairly simple.
?(...?)
This sets up a while(read() != EOF) loop. Then we simply have:
! Print input character.
8 Push 8.
^+ Duplicate, add. Gives 16.
^+ Duplicate, add. Gives 32.
! Print space.
Labyrinth, 10 bytes
<.23.%):,>
This terminates with an error, but the error messages goes to STDERR.
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).
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
PowerShell, 32 bytes
-join([char[]]$args[0]|%{"$_ "})
Explanation
Take in the input to the function and convert it to a char array. Add one space to each character and rejoin. Nothing really fancy here.
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.
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
𝔼𝕊𝕄𝕚𝕟, 5 chars / 7 bytes
ᴉü⬭+⬭
Short and sweet. Get input split along chars and join with space.
Befunge-98, 21 bytes
> ~:av
^,*84,w
@,*84,<
Lengthier than one already present but has the ending space requested by OP.
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."
Javascript, 35 chars
Full program
alert(prompt().replace(/./g,"$& "))
Javascript ES6, 24 chars
Just a function
s=>s.replace(/./g,"$& ")
Perl 5, 11 10 + 1 flags = 11 bytes
really, the same as the Perl 6 one, but the sed syntax changed.
s/./$& /g
example:
perl -pe "s/./$& /g" <<< abc
old:
perl -pne "s/(.)/\1 /g" <<< abc
O 1.2, 6 bytes
I' ]^o
Sample run:
bash-4.3$ java xyz.jadonfowler.o.O <(echo "I' ]^o") <<< 'Full width text.'
F u l l w i d t h t e x t .
This could be 5 characters in O 2 as IT]^o, but sadly it not seems to fully support the ^ command yet.
Convex, 3 bytes
Convex is a new language that I am developing that is heavily based on CJam and Golfscript. The interpreter and IDE can be found here. Input is an integer into the command line arguments. Indexes are one-based. Uses the CP-1252 encoding.
S*S
Explanation:
# Implied input
S* # Join by spaces
S # Add a space at the end
# Implied output
Additionally, @DonMuesli's CJam answer without the l (so Sf+) will also work for 3 bytes.
Clojure, 34 bytes
#(apply str(mapcat(fn[x][x" "])%))
Clojure is amazingly fun to work with but annoying to golf. Usually there's a really nice idiomatic solution to these challenges that isn't that many identifiers, but it's massive thanks to things like the identity function being identity (not fully golfed in these forms):
(defn fw [s] (apply str (interleave s (repeat " "))))
or
(defn fw [s] (apply str (mapcat (juxt identity (constantly " ")) s)))
RETURN, 10 bytes
`""¨{' °},
Takes input from STDIN. It's just take STDIN, split along chars, join with space, output.
Jolf, 7 bytes
p4i*li♣
p4 interweave
i the input
*li♣ with a string of spaces with = length to the input
Retina, 5
.
$&
Note the space at the end of the second line.
$& is equivalent to $0. Thanks to @mbomb007 for this link.
Reng v.1.2, 15 bytes
Try it out here! The input is given as "input".
ai p|$raoWo?!|~
a is a one-way mirror from the left. ai p| gets all input, $ drops the residual -1 not found input, r reverses the stack, and aoWo?!|~ is an output loop. W pushes 32, the space, and outputs it after outputting the character. ?! breaks out if not true, and ~ ends the program.
><>, 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
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...
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` `
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.
Ruby, 41 bytes
puts gets.chomp.chars.map{|e|e+" "}.join
chomp eats trailing newlines.
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
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
LiveScript, 17.
->"#{it/''*' '} "
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.
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
╰────────╯
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.
Java, 92
class T{public static void main(String[]A){System.out.print(A[0].replaceAll("(.)","$0 "));}}
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
CJam, 5 4 bytes
1 byte fewer thanks to @FryAmTheEggman
lSf+
Explanation
l e# read line
Sf+ e# map "concatenation" (+) with a space (S) as extra parameter
e# implicitly display characters in the stack
05AB1E, 4 bytes
Sð«J
Explanation
Sð«J
S split string into a list
ð« append a space to each element
J join
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.
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.
Seriously, 7 bytes
' ;,@j+
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



