3
\$\begingroup\$

Challenge closed, the shortest answer has been acccepted.

A military projection is a projection where all lengths and the angles in the X-Z plane remain unattuned.

Your task is to print a cube in military projection using /, |, \, -, and any whitespaces you want, given any integer greater than zero as it's side length. You can leave sides out that are not visible to the human eye. Here are some examples:

  /-\  
 /   \ 
|\   /| Side length:
| \ / | 2
 \ | / 
  \|/  

     /-\
    /   \
   /     \
  /       \
 /         \
|\         /|
| \       / | Side length:
|  \     /  |
|   \   /   | 5
|    \ /    |
 \    |    /
  \   |   /
   \  |  /
    \ | /
     \|/

 /-\  Side length:
|\ /| 
 \|/  1

(Printing the side lengths is not required.)

For the uppermost corner you must use the dash. As you can see, all sides are equal in length (when measured in characters). You may use any kind of spacing you wish, and omit any characters that don't change the appearance of the cube.

This is , so the shortest answer in bytes wins!

\$\endgroup\$
  • \$\begingroup\$ Are we guaranteed that the input is a positive integer? \$\endgroup\$ – Mr. Xcoder Jul 14 '17 at 19:58
  • \$\begingroup\$ Hello, and welcome to PPCG! I'm going to vote to close this question as unclear because there are some things you need to specify. For example, will the input always be a positive integer? What range of inputs are possible? What do smaller or larger inputs look like? Could you explain in more detail how to draw the cube, and also provide some more examples? If you clarify these, I'll remove my close vote. :) \$\endgroup\$ – DJMcMayhem Jul 14 '17 at 20:14
  • \$\begingroup\$ Hope I could satisfy your need for clarification. \$\endgroup\$ – racer290 Jul 15 '17 at 11:50
  • \$\begingroup\$ You can leave sides out that are not visible to the human eye. so, should we or not? You should specify that. \$\endgroup\$ – HyperNeutrino Jul 15 '17 at 19:44
3
\$\begingroup\$

Charcoal, 19 bytes

Nθ←¹↙θ↓θ→↘θ↑↑θ←↖θ‖B

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Python 2.7, 198 185 172 bytes

i=n=input();x=1;s,l,r,p='/|\ '
print p*n+'/-\\'
exec'x+=2;i-=1;print p*i+s+p*x+r;'*~-n+'i-=2;'+'i+=1;print l+p*i+r+p*x+s+p*i+l;x-=2;'*n+'print(n-i)*p+r+p*i+l+p*i+s;i-=1;'*n

Try it online!

Immense scope for golfing. I'm missing something out here, most probably!

Edit 1: -13 bytes: That's a start

Edit 2: -13 bytes: courtesy Erik the Outgolfer

\$\endgroup\$
  • 1
    \$\begingroup\$ Sadly, Python needs extra bytes for escaping the backslashes, but nice answer anyway! \$\endgroup\$ – racer290 Jul 15 '17 at 13:17
  • \$\begingroup\$ Thanks @racer290. Trying something out to see if it can be golfed any further. \$\endgroup\$ – Koishore Roy Jul 15 '17 at 13:19
  • \$\begingroup\$ '/|\\ '=>'/|\ ' \$\endgroup\$ – Zacharý Jul 15 '17 at 22:35
  • \$\begingroup\$ Some other -13... \$\endgroup\$ – Erik the Outgolfer Jul 16 '17 at 11:47
0
\$\begingroup\$

SOGL V0.12, 39 38 34 33 bytes

∫:┘ž}³№↕≥++┌.I1ž.┐∙:.2+.Iž0.I╬5╬⁷

Try it Here!

Explanation:

∫   }                              for 1-indexed range in the input
 :                                   duplicate current index
  ┘ž                                 at [index; index] in POP (by default the input, but in the 1st cycle it gets overwritten) insert a "\"
     ³                             triplicate that array of a big diagonal
      №↕                           mirror/reverse one of those vertically
        ≥                          put that at the stacks bottom
         ++                        join the three items together, resulting in the 3 diagonal lines of the result
           ┌.I1ž                   insert a dash at coordinates [input+1; 1] insert the dash
                .┐∙                get an array of vertical bars with the size of the input (aka a vertical bar)
                   :               duplicate that
                    .2+.Iž         at postition [input+2; input+1] insert the 2nd vertical bar in the 1st (resulting in the required vertical bars the correct distance apart)
                          0.I╬5    at position [0; input+1] insert the vertical bars without overwriting spaces; as the position numbers are 1-indexed this extends the array left
                               ╬⁷  palindromize horizontally, mirroring the required characters and with 1 overlap
\$\endgroup\$
  • \$\begingroup\$ Wow, creative solution! =) \$\endgroup\$ – racer290 Jul 15 '17 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.