34
\$\begingroup\$

I have an ASCII-art box and I need a program to open it.

Examples

Input:

-------
|     |
|_____|

Output:

      /
     /
    /
   /
  /
 /
/
|     |
|_____|

Specification

  • The first line will only consist of -, at least 3 of them
  • The middle rows will start with | have spaces, and end with |
    • All the middle rows will be the same
  • The last row will start with | have _ and end with a |
  • All rows will be the same length

Opening the box:

  • Each - should be replaced by a / in ascending lines and position.
\$\endgroup\$
16
  • 2
    \$\begingroup\$ As opposed to the game "Shut the Box"? \$\endgroup\$ Jan 31 '16 at 19:14
  • 1
    \$\begingroup\$ cough \$\endgroup\$ Jan 31 '16 at 21:24
  • 29
    \$\begingroup\$ The lid becomes twice as long when opened? Oh well, blame ASCII art. \$\endgroup\$ Jan 31 '16 at 21:46
  • 8
    \$\begingroup\$ What's in the box? \$\endgroup\$ Feb 1 '16 at 11:58
  • 2
    \$\begingroup\$ There's not a working interpreter, so I guess not then. Doesn't matter; when I do make the interpreter (soon, hopefully), I'll post the answer. \$\endgroup\$ Feb 1 '16 at 16:10

33 Answers 33

1
2
0
\$\begingroup\$

brainfuck, 118 bytes

-->+[<+>,----------]>>>++++[<++++++++>-]>-[<+>-----]++++++++++<----<<<<[[>+>+<<-]>[<+>-]>[>.<-]>>.>.[<]<<-]>>>>.>.[,.]

Try it online!

(You will have to check the "!" box to allow for everything after the ! to be considered input)

It is the same length as the Java answer, so I'm happy. Any help golfing it to be shorter than the Java answer would be greatly appreciated.

Explanation

-->+[<+>,----------]                                 Counts the number of characters until a linefeed
>>>++++[<++++++++>-]>-[<+>-----]++++++++++<----<<<<  Initialises the next 3 cells to 32 (space), 47 (/) and 10 (linefeed)
[                                                    Starts a loop on the length of the first line
[>+>+<<-]>[<+>-]>[>.<-]>>.>.[<]<<-                   Prints a space for every character and then prints a slash, a linefeed and then takes one from the number of characters, and repeats until that value is equal to zero
]                                                    Ends the loop
>>>>.>.[,.]                                          Prints the last slash, a newline and then the rest of the input
\$\endgroup\$
0
\$\begingroup\$

Brain-Flak, 144 bytes

({()<{}({}[((()()){}()){}])>}{}){(({}[()])<>){({}[()]<(((((()()){}){}){}){})>)}{}(((((()()()){}){}){}){}[()])(((()()){}()){})<>}{}<>{({}<>)<>}<>

Try it online!

The longest answer yet.

Explanation

({()<{}({}[((()()){}()){}])>}{}) #count the dashes "n"
{ #while N != 0
  (({}[()])<>) #copy --N to second stack for the next line
  {({}[()]<(((((()()){}){}){}){})>)}{} #indent
  (((((()()()){}){}){}){}[()]) # '/'
  (((()()){}()){}) # newline
  <>
}{}
<>{({}<>)<>}<> #copy output to main stack
\$\endgroup\$
0
\$\begingroup\$

Vyxal, 16 bytes

L:£(&‹¥\/꘍,)□Ḣ⁋,

Try it Online!

\$\endgroup\$
1
2

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.