# Carve some ASCII jewels!

March 13 is recognized as National Jewel Day, which is the theme of this challenge. So, given an integer n where n is greater than 0, create an ASCII jewel. For example:

n = 1          n = 2             n = 3
______
____             /      \
__                 /    \            \      /
/  \                \    /             \    /
\  /                 \  /               \  /
\/                   \/                 \/


The bottom is defined as the very bottom of the jewel to the highest pair of of \/. The rest is the top. For the above example where n = 1:

Bottom: \  /    Top:   __
\/           /  \


As you can see, the bottom is made of n + 1 layers of \/ with (1 * lines from the bottom) * 2 spaces in between with a maximum of n lines from the bottom of the jewel. If we take the second jewel (n = 2), we can see that:

 ____
/    \
\    /  2 (or n) layers from the bottom with 1*2*2 or 4 spaces in between \/
\  /   1 layer from the bottom with 1*1*2 or 2 spaces in between \/
\/    The bottom (0 layers) with 1*0*2 spaces or 0 spaces in between \/


The top is made of one pair of /\ with n*2 spaces in between with n*2 underscores on top.

Rules

• Must be able to take in any nonzero positive integers as user input
• Must create a jewel with the specs defined above (restated here):
• The top is made of one pair of /\ with n*2 spaces in between with n*2 underscores on top.
• The bottom is made of n + 1 layers of \/ with (1 * lines from the bottom) * 2 spaces in between with a maximum of n lines from the bottom of the jewel.
• Trailing newlines after the jewel, or trailing spaces on each line are allowed.
• No standard loopholes allowed

Winning Criteria

Least bytes wins!

• Strictly speaking "nonzero positive" is redundant -- if you wanted to include 0, you'd have to say "nonnegative". – Fund Monica's Lawsuit Mar 26 '17 at 23:27
• Can the answer be in PETSCII? – Shaun Bebbers Mar 27 '17 at 8:31
• As the number gets higher the "jewels" start to look less like jewels and more like pizza slices, or maybe that's just lunch time talking. – Marijn Stevering Mar 27 '17 at 9:52

# Charcoal, 17 bytes

Code:

ＮβＧ←β_↙↙¹→↘⁺β¹‖Ｍ→


Explanation:

Ｎβ                      # Place the input into β
Ｇ←β_                 # Draw a line of length β with _ as the filling character
↙                # Move the cursor one down and one left
↙¹              # Draw a line from the cursor position to one position ↙
→             # Move the cursor 1 to the right
⁺β¹         # Add one to the input and..
↘            # Create a line pointing ↘, with the size calculated above
‖Ｍ→     # Mirror to the right


A very neat command is ‖Ｍ, which also automatically mirrors / into \.

Uses the Charcoal encoding.

Try it online!

• That mirror command is really cool! Does it mirror brackets and other characters too? And is there a way to override that behavior? – DJMcMayhem Mar 26 '17 at 20:59
• @DJMcMayhem Yes and yes :) – Adnan Mar 26 '17 at 21:07
• Lol, you made diamonds out of charcoals! – SteeveDroz Mar 27 '17 at 6:55

# 05AB1E, 27 20 bytes

ƒN·ð×…\ÿ/}Â¹·'_×)R.c


Try it online!

Explanation

ƒ                      # for N in range[0 ... n]
N·ð×                  # push N*2 spaces
…\ÿ/              # push the string "\ÿ/" with "ÿ" replaced by the spaces
}             # end loop
Â            # push a reversed copy of the top of the stack
# (the largest row of the bottom of the diamond)
¹·'_×       # push input*2 underscores
)      # wrap the stack in a list
R     # reverse the list
.c   # join the list on newlines, padding each row to equal length

• Haha, nice! I believe you can change D„/\„\/‡ to Â. – Adnan Mar 26 '17 at 16:25
• @Adnan: Yes, I just realized that myself while working on an improvement :P – Emigna Mar 26 '17 at 16:27

# Python 2, 10198 95 bytes

lambda n:'\n'.join([' '+'__'*n,'/'+'  '*n+'\\']+[' '*i+'\\'+'  '*(n-i)+'/'for i in range(n+1)])


Try it Online!

Anonymous function that takes in a positive integer and returns a string

# Python 3.6, 92 bytes (Thanks to Ben Frankel)

lambda n:f' {"__"*n}\n/{"  "*n}\\\n'+'\n'.join(' '*i+'\\'+'  '*(n-i)+'/'for i in range(n+1))


I couldn't find an online interpreter for this version, but it is a bit shorter due to f-strings in v3.6

• You can save three bytes in Python 3.6: lambda n:f' {"__"*n}\n/{" "*n}\\\n'+'\n'.join(' '*i+'\\'+' '*(n-i)+'/'for i in range(n+1)). Taking advantage of f-strings. – Ben Frankel Mar 27 '17 at 4:32
• I am pretty sure repl.it has a test suite for Python 3 – Anthony Pham Mar 27 '17 at 21:20
• @AnthonyPham repl.it and TryItOnline both use Python 3.5, I've checked – math junkie Mar 27 '17 at 23:27
• Whoa, finally! I wonder what took Python so long. Every language deserves string interpolation ... – Felix Dombek Mar 28 '17 at 2:53

# PHP, 123 Bytes

echo($s=str_pad)(" ",$z=1+2*$a=$argv[1],_).$s("\n/",$z+1," ")."\\\n";for($i=0;$i<=$a;)echo$s($s("",$i)."\\",$z-$i++)."/\n";


## 143 Bytes first version

for(;$i<3+$a=$argv[1];$i++)echo 1-$i?str_pad("",$i?$i-2:1):"/",str_pad($i>1?"\\":"",$i<2?2*$a:2*($a-$i+2)+1,$i?" ":_),$i<2?$i?"\\":"":"/","\n";  Try it here! • Where can I try this? – Anthony Pham Mar 26 '17 at 16:15 • @AnthonyPham Here. – Adnan Mar 26 '17 at 16:17 • You can make it 119 bytes: ideone.com/RPCVZe – Tschallacka Mar 27 '17 at 14:21 • @Tschallacka if I assume that I use only a Linux Sytem – Jörg Hülsermann Mar 27 '17 at 14:32 • Well, as long as you don't edit with notepad.exe most editors have linux line endings... i.imgur.com/QZsmf4r.png windows console will happily display \n as a real newline. So yea, y ou can shave a few bytes of your answer. – Tschallacka Mar 27 '17 at 14:41 # V, 2827 26 bytes 1 bytes saved thanks to @DJMcMayhem by using > instead of É Ài__<esc>É ÙÒ r/Á\Ùr$r/òÙlxx>  <esc> is 0x1b Try it online! Hexdump: 00000000: c069 5f5f 1bc9 20d9 d220 722f c15c d972 .i__.. .. r/.\.r 00000010: 5c24 722f f2d9 6c78 783e$r/..lxx>  ### Explanation Top: Ài__<esc> " Write argument times __ É<space> " Prepend a space to the line Ù " Duplicate line below cursor, cursor also moves down Ò<space> " Replace every character with a space r/ " Change the first character in the line to a / Á\ " Append a \ to the end of the line  Bottom: Ù " Duplicate r\ " Change the first character in the line to a \$r/                    " Replace the last character with a /
ò                      " Until a breaking error occurs do:
Ù                    "  Duplicate
lxx                  "  Remove 2 middle characters (spaces)
>                    "  Indent by one space (implicit ending >)
" Implicit ending ò

• Nice answer! You can change É<space> to > which at the end of a macro is implicitly filled in to >> – DJMcMayhem Mar 26 '17 at 15:28
• @DJMcMayhem Nice suggestion! So the > indents one space instead of by one tab? – Kritixi Lithos Mar 26 '17 at 15:32
• Yep! That's cause I have set expandtab and set shiftwidth=1 – DJMcMayhem Mar 26 '17 at 15:39

# Röda, 71 bytes

f n{a=" ";[a,"__"*n,"
/",a*2*n,\
];seq n,0|[a*(n-_),\,a*2*_1,"/
"]}


Try it online!

## JavaScript (ES6), 80 bytes

f=

# C, 131 bytes

i;f(n){for(printf(" ",i=0);i++<n*2;)printf("_");for(printf("\n/%*c\n",n*2+1,92,i=0);i++<n+1;)printf("%*c%*c\n",i,92,(n-i)*2+3,47);}


Try it online!

• Where can I test this? – Anthony Pham Mar 26 '17 at 15:54
• Nice approach using printf's width to fill in the spaces. You can save 9 more bytes if you create a macro for the printf, remove the first i=0 and add a new variable j instead of re-initializing i to 0 on the second run: i,j;f(n){for(p(" ");i++<n*2;p("_"));for(p("\n/%*c\n",n*2+1,92);j++<n+1;p("%*c%*c\n",j,92,(n-j)*2+3,47));} – Claudiu Mar 27 '17 at 12:21
• @Claudiu Thanks, but then the function would produce correct output only when it is called for the first time, and IIRC that's against the rules here. The function should work no matter how many times it's called. – Steadybox Mar 27 '17 at 13:37
• @Steadybox oh I see, sorry for that. Does this apply for all codegolf questions? Looking just at this specific question it doesn't seem that it wants multiple inputs. – Claudiu Mar 27 '17 at 14:29

# Pyth, 44 Bytes

+" "*Q"__"++\/**2Qd\\jm+++*d\ \\**2-Qd\ \/hQ


try it!

### explanation

The code consists of 3 parts:

+" "*Q"__"               # pretty straightforward " "+input()*"__"
++\/**2Qd\\              # d is defined as " ":  "/"+2*input()*d+"\"
jm+++*d\ \\**2-Qd\ \/hQ  # The third part is a bit more complex so I'll explain it further:

jm                   hQ  # Map some lambda function onto range(input()+1) and join the result on newlines
+++*d\ \\**2-Qd\ \/    # Here d is the lambda argument (so I can't use it for spaces -.-)
+++*d\ \\**2-Qd\ \/    # In Python: d*" "+"\\"+2*(Q-d)*" "+"/"


# Python3, 104 bytes

n=int(input());print(" "+"__"*n+"\n/"+"  "*n+"\\")
for i in range(n+1):print(" "*i+"\\"+"  "*(n-i)+"/")


The program takes an integer from STDIN and returns the jewel into STDOUT.

# Pip, 43 bytes

42 bytes of code, +1 for -n flag.

Ps.'_Xa*2P"/\"JsXa*2sX_.'\.sXa-_X2.'/M,a+1


Takes input as a command-line argument. Try it online!

### Explanation

Constructs the first two lines separately, then the rest of the jewel with a map operation:

Ps.'_Xa*2
a*2  Cmdline arg, times 2
'_X     That many underscore characters
s.        Concatenated to a space character
P          Print (with newline)

P"/\"JsXa*2
a*2  Cmdline arg, times 2
sX     That many space characters
"/\"J       Join the string "/\" with the above as the separator
P            Print (with newline)

sX_.'\.sXa-_X2.'/M,a+1
,a+1  Numbers from 0 up to and including a
M      Map the following lambda function:
sX_                      Space, repeated (fn arg) times
.'\                   Concatenate \
.                  Concatenate:
sXa-_              Space, repeated (a - (fn arg)) times
X2            repeated twice
.'/        Concatenate /
Print result list, newline separated (implicit, -n flag)


### Another solution

Also 42+1 bytes, this time with the -l flag:

Ys.tAL'_.sX2+,a.0(yALRVyRXD1-_)R0'\R1'/ZDs


TIO

# Pyth, 38 bytes

j[*yQ\_j*yQpd"/\\"jm+*\ dj*\ y-Qd"\/"h


# C, 115 bytes

#define p printf(
i;j;f(n){for(p" ");i++<n;p"__"));for(p"\n/%*c",2*n+1,92);j<=n;p"\n%*c%*c",++j,92,n*2-j*2+3,47));}


Try it online!

# C, 123 bytes

Though the challenge doesn't require it, at the expense of 8 bytes the function can be made reusable (the first solution saves 8 bytes by relying on the implicit initialization of global variables).

#define p printf(
i;f(n){for(i=0,p" ");i++<n;p"__"));for(i=0,p"\n/%*c\n",2*n+1,92);i<=n;p"%*c%*c\n",++i,92,n*2-i*2+3,47));}


Try it online!

## Batch, 152 bytes

@set s=
@for /l %%i in (1,1,%1)do @call set s=  %%s%%
@echo  %s: =_%
@echo /%s%\
@set s=\%s%/
:l
@echo %s%
@if %s:~-2%==/ set s=%s:\  = \%&goto l


Tests:

n = 1
__
/  \
\  /
\/

n = 2
____
/    \
\    /
\  /
\/

n = 3
______
/      \
\      /
\    /
\  /
\/

• I will need a test suite to test this out. – Anthony Pham Mar 27 '17 at 21:19

C#, 187 bytes

I'm sure there is a more compact solution out there but this is my first attempt:

var a=" "+new string('_',2*n)+"\n/"+new string(' ',2*n)+"\\\n";for(int i=n;i>0;i--){a+=new string(' ',n-i)+"\\"+new string(' ',2*i)+"/\n";}a+=new string(' ',n)+"\\/";Console.Write(a);


Try it online..

• I will need a test suite to test this out. – Anthony Pham Mar 27 '17 at 21:18

## JavaScript (ES6), 93 bytes

n=>( 0
/2\\+
1\\4/.repeat(k=++n)).replace(/\d/g,c=>' _'[+!+c].repeat(c&1?k-n-2:+c+--n*2))


### Demo

let f =

n=>( 0
/2\\+
1\\4/.repeat(k=++n)).replace(/\d/g,c=>' _'[+!+c].repeat(c&1?k-n-2:+c+--n*2))

console.log(f(1))
console.log(f(2))
console.log(f(3))

# dc, 121 bytes

?d1+sa2*sb32P[0sq[lvPlq1+dsqlj>h]shlj0<h]srlbsj95svlrx2607Plbsj32svlrx[\]p0sd[ldsjlrx92Plbsjlrxlb2-sb[/]pld1+dsdla>k]dskx


Try it online!

# Perl 5 109 94 + 1 (for flag -p) = 95 Bytes

Try it Online!

$l=$_*2;$s=" "."_"x$l."\n/"." "x$l."\\\n";$s.=" "x$_."\\"." "x($l-$_*2)."/\n"for 0..$_;print$s  Can be run like so: perl -p <name of file> <<< n  Ungolfed $l=$_*2;$s=" "."_"x$l."\n/"." "x$l."\\\n";
$s.=" "x$_."\\"." "x($l-$_*2)."/\n"for 0..$_; print$s


Explanation

#Sets $l to twice the value of the input 'n'$l=$_*2; #Top 2 rows of jewel adding$l underscores then newline
#followed by '/' and $l spaces. The '\\\n' is an escaped '\' and a newline$s=" "."_"x$l."\n/"." "x$l."\\\n";

#The meat of the jewel generation.  It contains a for-loop
#that iterates from 0 to $_ (the input value 'n') #The loop uses its iterator value ($_ (which overrides the outer $_)) #to determine how many leading spaces it needs to apply. #Then it adds a '\' with '\\' followed by$l-$_*2 number of spaces #(the inside of the jewel). Again, while under the umbrella of the for-loop, #the$_ refers to the iterator value of the for-loop.
#After the inner spaces, it goes on to add in the '/' and a new line
$s.=" "x$_."\\"." "x($l-$_*2)."/\n"for 0..$_; #Lastly, it prints the compiled Scalar value$s.  (In Perl, Strings are Scalar values or references
print\$s
`
• I will need a test suite to test this out as not everyone quite understands or has the ability to run this the way you have stated – Anthony Pham Mar 27 '17 at 21:19
• @AnthonyPham I added the Try It Online link – CraigR8806 Mar 28 '17 at 14:50