1
\$\begingroup\$

Basically, between every character of a uni-line string, add a space, but there can't be two spaces in between one character.

  • aesthetic becomes a e s t h e t i c.

  • The quick brown fox jumps over the lazy dog becomes T h e q u i c k b r o w n f o x j u m p s o v e r t h e l a z y d o g.

  • I'm Nobody! Who are you? becomes I ' m n o b o d y ! W h o a r e y o u ?

This is code golf, so the shortest answer in bytes wins.

\$\endgroup\$
9
  • \$\begingroup\$ PS this is my first challenge. Any feedback would be very helpful! \$\endgroup\$
    – bleh
    Jan 12 '17 at 2:38
  • \$\begingroup\$ Would it be acceptable to output one extra trailing space? Will there ever be newlines in the input? \$\endgroup\$
    – DJMcMayhem
    Jan 12 '17 at 2:44
  • \$\begingroup\$ No newlines, yes to extra space \$\endgroup\$
    – bleh
    Jan 12 '17 at 2:44
  • \$\begingroup\$ We can assume input will always be printable ascii? Can input be a char array? \$\endgroup\$
    – Pavel
    Jan 12 '17 at 2:47
  • 3
    \$\begingroup\$ Welcome to PPCG. Since you're asking for feedback - 1) This is a very simple challenge that (as you can see from all the quick, short answers) is trivial to answer in many languages. 2) Consider posting challenges to the sandbox first to get more constructive feedback before the challenge officially opens. \$\endgroup\$ Jan 12 '17 at 3:14
2
\$\begingroup\$

Jelly, 3 bytes

ḟ⁶K

ilter out spaces () then join by space (K).

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Or ḲFK for the same byte count. \$\endgroup\$
    – Dennis
    Jan 12 '17 at 3:09
2
\$\begingroup\$

Python, 36 bytes

lambda s:" ".join(s.replace(" ",""))
\$\endgroup\$
2
  • \$\begingroup\$ Ninja'd me by a byte, I used lambda s:" ".join(''.join(s.split())) :P \$\endgroup\$
    – FlipTack
    Jan 12 '17 at 22:29
  • \$\begingroup\$ 31: print(*input().replace(' ','')) \$\endgroup\$
    – Makonede
    Jun 7 '21 at 20:23
2
\$\begingroup\$

Retina, 8

 

.
$0  

Whitespace is significant - there are single spaces at the end of the first and last lines.

Try it online.

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

Pyth, 4 bytes

jdsc

Splitting on whitespace and then joining seems shorter than removing the spaces.

In pseudocode:

'     ' d,Q = " ",input()  # preinitialized variables
'jd   ' d.join(
'  s  '     sum(
'   cQ'         Q.split() ))

Try it online!

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

Haskell, 22 bytes

(((:" ")=<<)=<<).words

Laikoni saved 2 bytes with a nice use of words. Previous answer:

(=<<)(:" ").filter(>' ')

Try it online

\$\endgroup\$
1
  • \$\begingroup\$ (((:" ")=<<)=<<).words is two bytes shorter. \$\endgroup\$
    – Laikoni
    Jan 12 '17 at 9:18
0
\$\begingroup\$

V, 7 bytes

Íó*/ 
X

Try it online!

Just a straightforward regex, and an "X" to delete one leading space.

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

tcl, 28

puts [split [join $s ""] ""]

testable on http://rextester.com/VFP77495

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.