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
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Tile pyramids on top of each other!

+4
−0

The task

Given a positive integer as input, output tiled pyramids of this height.

How?

Let's say the inputted integer was n. From there, we output n lines of output, each having:

  1. A decreasing indentation of spaces starting with n-1 spaces and ending with 0 spaces
  2. An increasing number of the symbol / starting with 1 symbol and ending with n symbols
  3. An increasing number of the symbol \ starting with 1 symbol and ending with n symbols

For example, with an input of 4, the output should be the following:

   /\
  //\\
 ///\\\
////\\\\

Rules

  1. You may output an optional newline after the required output
  2. Input will always be a positive integer
  3. This is code-golf, so lowest byte-count for each language is the winner

Test cases

Input: 1
Output:
/\


Input: 7
Output:
      /\
     //\\
    ///\\\
   ////\\\\
  /////\\\\\
 //////\\\\\\
///////\\\\\\\


Input: 11
Output:
          /\
         //\\
        ///\\\
       ////\\\\
      /////\\\\\
     //////\\\\\\
    ///////\\\\\\\
   ////////\\\\\\\\
  /////////\\\\\\\\\
 //////////\\\\\\\\\\
///////////\\\\\\\\\\\
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Is the input being a Unicode character (e.g. a newline means 10, "!" means 33, etc) allowed? (1 comment)

9 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+3
−0

V (vim), 11 bytes

ÀñY>HGpé/Á\

Try it online!

Hexdump:

00000000: c380 fe58 c3b1 593e 4847 70c3 a92f c381  ...X..Y>HGp../..
00000010: 5cc3 bfc3                                \...
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+3
−0

AppleScript, 264 bytes

Sue me. It works.

set n to text returned of (display dialog "" default answer "") as number
set o to ""
repeat with i from 1 to n
   repeat (n-i) times
      set o to o&" "
   end repeat
   repeat i times
      set o to o&"/"
   end repeat
   repeat i times
      set o to o&"\\"
   end repeat
   set o to o&"\n"
end repeat
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+2
−0

Vyxal C, 6 bytes

ƛ\/*øṀ

Try it Online!

ƛ      # 1...n map
 \/*   # That many /
    øṀ # Ascii art mirror
       # (C flag) Join by newlines and center
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+2
−0

Japt -R, 12 bytes

õÈ"/\\"mpXÃû

Try it

õÈ"/\\"mpXÃû    :Implicit input of integer
õ               :Range [1,input]
 È              :Map each X
  "/\\"         :  Literal string
       m        :  Map
        pX      :    Repeat X times
          Ã     :End map
           û    :Centre pad each to the length of the longest
                :Implicit output joined with newlines
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+2
−0

Ruby, 43 bytes

->n{(1..n).map{|i|" "*(n-i)+?/*i+?\\*i}*$/}

->n{                                      }  # lambda
    (1..n).map{|i|                    }      # map over 1 to n
                  " "*(n-i)+?/*i+?\\*i       # spaces plus / plus \
                                       *$/   # join with newline

Try it online!

The special global variable $/ is initialized to newline by default, which is shorter than ?\n or "\n".

From globals.rdoc:

$/

The input record separator, newline by default. Aliased to $-0.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Python 2, 57 bytes

a,x=1,input()
exec'print" "*(x-a)+"/"*a+"\\\\"*a;a+=1;'*x

Prints it out line by line

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

How does it work ? (1 comment)
+1
−0

Canvas, 9 7 bytes

H/×║∔}r

Try it here!

Explanation

H/×║+}r
H    }   push empty art and start a loop from 1..n
 /×      repeat '/' i times
   ║     palindromize horizontally(no overlap)
    +    join with previous iteration
      r  center the whole thing 
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

C (compliant), 106 bytes

char r,i,s[80];void f(int n){memset(s,32,79);for(;r<n;puts(s),r++)for(i=0;i++<n*2;s[n-r-1]=47,s[n+r]=92);}

Try it online!

Standard C compliant function solution.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

JavaScript (Node.js), 57 56 bytes

f=(a,b='/\\')=>a--?''.padEnd(a)+b+`
`+f(a,'/'+b+'\\'):''

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »