Skip to main content
added 3 characters in body
Source Link
Jakube
  • 21.9k
  • 3
  • 27
  • 108

Pyth, 39 3838 36 bytes

IKjbmXXj\|m*\jbXmXXj\|m*\ Q2d\\_hd\/QK)j\Om*Q\JhyQQX*\-2_KJQ\O

Try it online: [Pyth Compiler/Executor][1]

Sadly I had to waste 3 2 bytes for not printing a leading newline for N = 0.Pyth Compiler/Executor

jbXmXXj\|m*\ Q2d\\_hd\/JhyQQX*\-JQ\O   mimplicit: Q = input
                Q    map each d ofJhyQ [0, 1, ..., input-1] to:       J = 1 + 2*Q
    m       *\ Q          J      " "*input        map each d of [0,1,...,2*Q] to:
          m*\ Q   2               list with twice       " "*input
       j\|  m    2               join this list by "|"
      X list with twice " "*input
    d\\  j\|          replace the value at d to "\"
     X           join this _hd\/list by "|"
     replaceX the value at -(d+1) to "/"
  jb d\\                       replace jointhe byvalue "\n"at d to "\"
 K   X             _hd\/           store in K
IK     replace the value at -(d+1) to "/"
  X          K)  if K: print K (this avoids a leading newline, if N=0)

  Q  *Q\-         replace line Q by:
        "-"*input
   m    2              *\-J     list with twice "-"*input"*J
j\O                         join by "O" andX print 

   Q\O     replace element at Q _Kwith "O"
jb                print K in reverse order
                 join by "newlines"

[1]Another 36 bytes solution would be: https://pyth.herokuapp.com/?code=IKjbmXXj%5C%7Cm*%5C+Q2d%5C%5C_hd%5C%2FQK)j%5COm*Q%5C-2_K&input=3&debug=0

jbmXXj\|m*?\-KqdQ\ Q2d\\_hd?\OK\/hyQ

Pyth, 39 38 bytes

IKjbmXXj\|m*\ Q2d\\_hd\/QK)j\Om*Q\-2_K

Try it online: [Pyth Compiler/Executor][1]

Sadly I had to waste 3 2 bytes for not printing a leading newline for N = 0.

    m                   Q    map each d of [0, 1, ..., input-1] to:
           *\ Q                " "*input
          m    2               list with twice " "*input
       j\|                     join this list by "|"
      X         d\\            replace the value at d to "\"
     X             _hd\/       replace the value at -(d+1) to "/"
  jb                         join by "\n"
 K                           store in K
IK                       K)  if K: print K (this avoids a leading newline, if N=0)

    *Q\-                    "-"*input
   m    2                   list with twice "-"*input
j\O                         join by "O" and print 

          _K                 print K in reverse order
              

[1]: https://pyth.herokuapp.com/?code=IKjbmXXj%5C%7Cm*%5C+Q2d%5C%5C_hd%5C%2FQK)j%5COm*Q%5C-2_K&input=3&debug=0

Pyth, 39 38 36 bytes

jbXmXXj\|m*\ Q2d\\_hd\/JhyQQX*\-JQ\O

Try it online: Pyth Compiler/Executor

jbXmXXj\|m*\ Q2d\\_hd\/JhyQQX*\-JQ\O   implicit: Q = input
                       JhyQ            J = 1 + 2*Q
    m                  J               map each d of [0,1,...,2*Q] to:
          *\ Q                           " "*input
         m    2                          list with twice " "*input
      j\|                                join this list by "|"
     X         d\\                       replace the value at d to "\"
    X             _hd\/                  replace the value at -(d+1) to "/"
  X                        Q           replace line Q by:
                             *\-J        "-"*J
                            X    Q\O     replace element at Q with "O"
jb                                     join by "newlines"

Another 36 bytes solution would be:

jbmXXj\|m*?\-KqdQ\ Q2d\\_hd?\OK\/hyQ
added 54 characters in body
Source Link
Jakube
  • 21.9k
  • 3
  • 27
  • 108

Pyth, 3939 38 bytes

KjbmXXj\|m*\IKjbmXXj\|m*\ Q2d\\_hd\/QIQKQK)j\Om*Q\-2_K

Try it online: [Pyth Compiler/Executor][1]

Sadly I had to waste 33 2 bytes for not printing a leading newline for N = 0.

Explanation

    m                   Q    map each d of [0, 1, ..., input-1] to:
           *\ Q                " "*input
          m    2               list with twice " "*input
       j\|                     join this list by "|"
      X         d\\            replace the value at d to "\"
     X             _hd\/       replace the value at -(d+1) to "/"
  jb                         join by "\n"
 K                           store in K
 
IQK)IK                       K)  if inputK: print K
  (this avoids a leading newline, if N=0)

    *Q\-                    "-"*input
   m    m2    2               list with twice "-"*input
j\O    j\O                     join by "O" and print 

         _K    _K             print K in reverse order
              

[1]: https://pyth.herokuapp.com/?code=KjbmXXj%5C%7Cm*%5C%20Q2d%5C%5C_hd%5C%2FQIQKhttps://pyth.herokuapp.com/?code=IKjbmXXj%5C%7Cm*%5C+Q2d%5C%5C_hd%5C%2FQK)j%5COm*Q%5C-2_K&input=3&debug=0

Pyth, 39 bytes

KjbmXXj\|m*\ Q2d\\_hd\/QIQK)j\Om*Q\-2_K

Try it online: [Pyth Compiler/Executor][1]

Sadly I had to waste 3 bytes for not printing a leading newline for N = 0.

Explanation

   m                   Q    map each d of [0, 1, ..., input-1] to:
          *\ Q                " "*input
         m    2               list with twice " "*input
      j\|                     join this list by "|"
     X         d\\            replace the value at d to "\"
    X             _hd\/       replace the value at -(d+1) to "/"
 jb                         join by "\n"
K                           store in K
 
IQK)                        if input: print K
         *Q\-                "-"*input
       m    2               list with twice "-"*input
    j\O                     join by "O" and print
             _K             print K in reverse order
              

[1]: https://pyth.herokuapp.com/?code=KjbmXXj%5C%7Cm*%5C%20Q2d%5C%5C_hd%5C%2FQIQK)j%5COm*Q%5C-2_K&input=3&debug=0

Pyth, 39 38 bytes

IKjbmXXj\|m*\ Q2d\\_hd\/QK)j\Om*Q\-2_K

Try it online: [Pyth Compiler/Executor][1]

Sadly I had to waste 3 2 bytes for not printing a leading newline for N = 0.

Explanation

    m                   Q    map each d of [0, 1, ..., input-1] to:
           *\ Q                " "*input
          m    2               list with twice " "*input
       j\|                     join this list by "|"
      X         d\\            replace the value at d to "\"
     X             _hd\/       replace the value at -(d+1) to "/"
  jb                         join by "\n"
 K                           store in K
IK                       K)  if K: print K (this avoids a leading newline, if N=0)

    *Q\-                    "-"*input
   m    2                   list with twice "-"*input
j\O                         join by "O" and print 

         _K                 print K in reverse order
              

[1]: https://pyth.herokuapp.com/?code=IKjbmXXj%5C%7Cm*%5C+Q2d%5C%5C_hd%5C%2FQK)j%5COm*Q%5C-2_K&input=3&debug=0

Source Link
Jakube
  • 21.9k
  • 3
  • 27
  • 108

Pyth, 39 bytes

KjbmXXj\|m*\ Q2d\\_hd\/QIQK)j\Om*Q\-2_K

Try it online: [Pyth Compiler/Executor][1]

Sadly I had to waste 3 bytes for not printing a leading newline for N = 0.

Explanation

   m                   Q    map each d of [0, 1, ..., input-1] to:
          *\ Q                " "*input
         m    2               list with twice " "*input
      j\|                     join this list by "|"
     X         d\\            replace the value at d to "\"
    X             _hd\/       replace the value at -(d+1) to "/"
 jb                         join by "\n"
K                           store in K

IQK)                        if input: print K
        *Q\-                "-"*input
       m    2               list with twice "-"*input
    j\O                     join by "O" and print
             _K             print K in reverse order
              

[1]: https://pyth.herokuapp.com/?code=KjbmXXj%5C%7Cm*%5C%20Q2d%5C%5C_hd%5C%2FQIQK)j%5COm*Q%5C-2_K&input=3&debug=0