Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

I done did made a spaceship maw!

Introduction:

Inspired by this comment of @MagicOctopusUrn on @Emigna's 05AB1E answer for my "It was just a bug" challenge:

×ばつý}».∊ I done did made a spaceship maw! And I was all excited about suggesting a 12-byte edit. – Magic Octopus Urn Jul 17 '17 at 20:10

Which is a 05AB1E (legacy) program resulting in this:

1234567890
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1234567890

Try it online.

Challenge:

Input: A non-empty string

Output: From outwards going inwards, add one more space between each character every line, similar as done in the output above, equal to the length - 1. So for an input 1234567890 the output would actually be this instead:

1234567890
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0 
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
1234567890

Why? The length of 1234567890 is 10. So we start by outputting 10 lines: the first line without spaces; second with one space delimiter; third with two; etc. And then (without have the middle line with length - 1 spaces duplicated), we go back to the initial input while going down.

Challenge rules:

  • Input is guaranteed to be non-empty (a length >= 1). (For single char inputs we simply output that character.)
  • Any amount of trailing/leading spaces/newlines are allowed, as long as the output itself (wherever on the screen) is correct. (Empty line(s) in between output lines also isn't allowed.)
  • Input will only contain printable ASCII characters excluding whitespaces (code-point range [33, 126])
  • I/O is flexible. Input may be taken as STDIN, argument, or function parameter. May be a list/array/stream of characters instead of string. Output may also be a list/array/stream of characters instead of strings; may be printed to STDOUT; returned as newline-delimited string; etc.

General rules:

  • This is , so shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code.
  • Also, adding an explanation for your answer is highly recommended.

Test cases:

Input: @
Output:
@
Input: test
Output:
test
t e s t
t e s t
t e s t
t e s t
t e s t
test
Input: ?!
Output:
?!
? !
?!
Input: Spaceship
Output:
Spaceship
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
S p a c e s h i p
Spaceship
Input: 05AB1E
Output:
05AB1E
0 5 A B 1 E
0 5 A B 1 E
0 5 A B 1 E
0 5 A B 1 E
0 5 A B 1 E
0 5 A B 1 E
0 5 A B 1 E
0 5 A B 1 E
0 5 A B 1 E
05AB1E
Input: )}/\
Output:
)}/\
) } / \
) } / \
) } / \
) } / \
) } / \
)}/\

Answer*

Draft saved
Draft discarded
Cancel
12
  • \$\begingroup\$ You can drop the S. Input is flexible, so inputting as list is allowed. \$\endgroup\$ Commented Sep 4, 2018 at 14:26
  • 1
    \$\begingroup\$ @KevinCruijssen: Your first version is 9 bytes in legacy though, as » can be omitted. \$\endgroup\$ Commented Sep 4, 2018 at 16:22
  • 1
    \$\begingroup\$ Yours actually works in the legacy in 9 bytes as well if you remove » and change the loop v to a map ε. \$\endgroup\$ Commented Sep 4, 2018 at 17:04
  • 1
    \$\begingroup\$ Posted the answer. And currently Japt is beating us with 6 bytes I'm afraid. Or did you mean shortest in 05AB1E (Elixir rewrite) and 05AB1E (Python legacy)? :) \$\endgroup\$ Commented Sep 4, 2018 at 21:09
  • 2
    \$\begingroup\$ Does εINð×ý}û» also work? \$\endgroup\$ Commented Sep 4, 2018 at 21:20

AltStyle によって変換されたページ (->オリジナル) /