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.
Thanks to Dennis for saving 2 bytes. Code:
j⁶⁶
Explanation:
j⁶ # Join the list by spaces. ⁶ # Appends a space to the final output.
Sð«J
Explanation
Sð«J S split string into a list ð« append a space to each element J join
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.
?=?
Sample run:
bash-4.3$ gema '?=? ' <<< 'Full width text.' F u l l w i d t h t e x t .
Java, 99 bytes
Can you feel the overhead tonight?
class Tpublic static void main(String[]a)for(char c:a[0].toCharArray())System.out.print(c+" ");
53 characters for a lambda but that doesn’t meet the program requirement.
s->for(char c:s.toCharArray())System.out.print(c+" ")
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
Saved 8 bytes thanks to FryAmTheEggman for reminding me about a very useful tip. Code:
,<.I;/@.>6~;
Or in a more readable form:
, < . I ; / @ . > 6 ~ ; . . . . . .
I have no idea why, but this does seem to print a space character in the end. Can definitely be golfed further.
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
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
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.
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
Simple, I just wish that Array.join added the space to the end so I could save 3 bytes.
s=>[...s].join` `+` `
Convex, 3 bytes
S*S
On my phone atm, will update this post later.
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
Related
Full Width Text – codegolf.stackexchange.com #JHedzWorlD
No comments:
Post a Comment