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*

Create a cactus from words

Introduction:

A typical cartoonish cactus usually looks like this:

enter image description here

One big stem in the middle, with some L-shaped branches sticking out.

We'll use this general shape for this challenge.

Challenge:

Given a pair of words, create an ASCII-art cactus with two upside down alphabets as stem. The first word is the left branch and the second word is the right branch:

E.g. input = ["cartoonish","testing"], will result in the following cactus:

 zz
 yy
 xx g
 ww n
 vv i
 uu t
 ttes
 ss
 rr
 qq
 pp
 oo
 nn
 mm
 ll
 kk
h jj
s ii
i hh
n gg
o ff
o ee
t dd
racc
 bb
 aa

The first letter of the words are part of the stem; then it'll grow out two letters; and continue upwards for the remaining letters.

Challenge rules:

  • The words will have a guaranteed length of \5ドル \leq L \leq 99\$
  • The words can start with an a or z, even though the resulting cactus might look pretty ridiculous that way; they can also start with the same letter or even be the same.
  • A word can tower above the stem (e.g. yoghurt).
  • Although leading spaces to have the correct shape are of course mandatory, one or more (additional) leading/trailing spaces or newlines are allowed. As long as the correct cactus is somewhere on the screen, it's fine.
  • All the letters may be uppercase instead of lowercase, as long as its consistent across the entire 'cactus'.
  • Output format is flexible, so can be printed to STDOUT; returned as a string; returned as a character-matrix; etc.

General Rules:

  • This is , so the 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 with default I/O rules, 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 (e.g. TIO or ATO).
  • Also, adding an explanation for your answer is highly recommended.

Test Cases:

Input: ["cartoonish","testing"]
Output:

 zz
 yy
 xx g
 ww n
 vv i
 uu t
 ttes
 ss
 rr
 qq
 pp
 oo
 nn
 mm
 ll
 kk
h jj
s ii
i hh
n gg
o ff
o ee
t dd
racc
 bb
 aa

Input: ["yoghurt","antidisestablishmentarianism"]
Output:

t
r
u
h zz m
goyy s
 xx i
 ww n
 vv a
 uu i
 tt r
 ss a
 rr t
 qq n
 pp e
 oo m
 nn h
 mm s
 ll i
 kk l
 jj b
 ii a
 hh t
 gg s
 ff e
 ee s
 dd i
 cc d
 bb i
 aant

Input: ["cactus","stems"]
Output:

 zz
 yy
 xx
 ww
 vv
 uu s
 tt m
 sste
 rr
 qq
 pp
 oo
 nn
 mm
 ll
 kk
 jj
 ii
 hh
 gg
s ff
u ee
t dd
cacc
 bb
 aa

Input: ["duplicate","duplicate"]
Output:

 zz
 yy
 xx
 ww
 vv
 uu
 tt
 ss
 rr
 qq
 pp
 oo
 nn
 mm
 ll
 kk
e jj e
t ii t
a hh a
c gg c
i ff i
l ee l
puddup
 cc
 bb
 aa

Answer*

Draft saved
Draft discarded
Cancel
4
  • \$\begingroup\$ ⇌⍉⬚@ (⊂⇌∩(⊂+@a⇡26≡⊂:⊟°⊂:¤↯:@ -@a°⊂)), 36 bytes \$\endgroup\$ Commented Mar 19, 2024 at 17:45
  • \$\begingroup\$ @Joao-3 nice idea, for some reason it hadn’t occurred to me that i could use fill on the whole thing, and just simplify the whole joining process. thanks! \$\endgroup\$ Commented Mar 19, 2024 at 17:58
  • \$\begingroup\$ That code on the code block is outdated though \$\endgroup\$ Commented Mar 19, 2024 at 18:02
  • \$\begingroup\$ @Joao-3 good catch, fixed \$\endgroup\$ Commented Mar 19, 2024 at 18:04

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