Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users

Dashboard
Notifications
Mark all as read
Challenges

Word Set Square

+5
−0

Challenge

Given a string, e.g. Hello, do the following:

Mirror it:

Hello -> HelloolleH

and create a right triangle using it as the sides:

H         
ee        
l l       
l  l      
o   o     
o    o    
l     l   
l      l  
e       e 
HelloolleH

Which looks sort of like a set square.

That's it!

Scoring

This is code-golf. Shortest answer in each language wins.

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

5 answers

+4
−0

APL (Dyalog Unicode), 23 bytes

Anonymous tacit prefix function. Reuires 0-based indexing (⎕IO←0)

(⊢⍪⍨¯1↓⊢,∘↑-∘⍳∘≢↑¨⊢)⊢,⌽

Try it online!

 reverse the argument

⊢, prepend the argument

() apply the following tacit function to that:

 on the characters of the argument

 …↑¨ of each character, take this many characters:

  -∘⍳∘≢ the negative indices $0…\text{length}-1$

 …∘↑ mix list of strings into character matrix, then:

  ⊢, prepend the argument (vertically)

¯1↓ drop the last row

⊢⍪⍨ append the argument below

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

V (vim), 23 bytes

æw|PòlÄxòjVLkîyllv$r $Ð

Try it online!

Hexdump:

00000000: e677 7c50 f26c c478 f26a 564c 6bee 796c  .w|P.l.x.jVLk.yl
00000010: 6c76 2472 2024 d0                        lv$r $.
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

Scala, 99 bytes

s=>{val x=s+s.reverse
s(0)+"\n"+x.tail.init.zipWithIndex.map{case(c,i)=>c+" "*i+c+"\n"}.mkString+x}

Try it in Scastie!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

Haskell, 110 bytes

f a=s>>=(#)$a++reverse a
[email protected](a:b)!f=f c:b!f
_!_=[]
f#n=n!((n!).f)
s(p:q)(d:e)(b:c)|e==c||e==[]=b|q==c=d|0<1=' '

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+1
−0

Japt -R, 16 15 bytes

ê1
¬ËúEÄ hJDÃÆU

Try it

ê1\n¬ËúEÄ hJDÃÆU     :Implicit input of string U
ê1                   :Mirror
  \n                 :Reassign to variable U
    ¬                :Split
     Ë               :Map each D at 0-based index E
      ú              :  Left pad with spaces to length
       EÄ            :    E+1
          h          :  Replace the character at index ...
           J         :  -1 (i.e., the last) with ...
            D        :  D
             Ã       :End map
              ÆU     :Modify the last element and return U
                     :Implicit output joined with newlines
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

General comments (3 comments)

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!