Tile pyramids on top of each other!
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:
- A decreasing indentation of spaces starting with
n-1
spaces and ending with0
spaces - An increasing number of the symbol
/
starting with1
symbol and ending withn
symbols - An increasing number of the symbol
\
starting with1
symbol and ending withn
symbols
For example, with an input of 4, the output should be the following:
/\
//\\
///\\\
////\\\\
Rules
- You may output an optional newline after the required output
- Input will always be a positive integer
- 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:
/\
//\\
///\\\
////\\\\
/////\\\\\
//////\\\\\\
///////\\\\\\\
////////\\\\\\\\
/////////\\\\\\\\\
//////////\\\\\\\\\\
///////////\\\\\\\\\\\
[V (vim)], 11 bytes ÀñY …
4y ago
AppleScript, 264 bytes Sue …
4y ago
Vyxal `C`, 6 bytes ``` ƛ\/ …
3y ago
[Ruby], 43 bytes -> …
4y ago
Japt `-R`, 12 bytes õÈ" …
4y ago
C (compliant), 106 bytes …
4y ago
[Python 2], 57 bytes …
4y ago
Canvas, 9 7 bytes H/×║∔} …
4y ago
[JavaScript (Node.js)], 57 56 …
4y ago
9 answers
V (vim), 11 bytes
ÀñY>HGpé/Á\
Hexdump:
00000000: c380 fe58 c3b1 593e 4847 70c3 a92f c381 ...X..Y>HGp../..
00000010: 5cc3 bfc3 \...
0 comment threads
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
0 comment threads
Vyxal C
, 6 bytes
ƛ\/*øṀ
ƛ # 1...n map
\/* # That many /
øṀ # Ascii art mirror
# (C flag) Join by newlines and center
0 comment threads
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
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
.
0 comment threads
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);}
Standard C compliant function solution.
0 comment threads
Python 2, 57 bytes
a,x=1,input()
exec'print" "*(x-a)+"/"*a+"\\\\"*a;a+=1;'*x
Prints it out line by line
JavaScript (Node.js), 57 56 bytes
f=(a,b='/\\')=>a--?''.padEnd(a)+b+`
`+f(a,'/'+b+'\\'):''
1 comment thread