15
\$\begingroup\$

Remove one stick and output the stack updated.

Description

You can remove only sticks on top( completely drawn).

You can assume:

  • there are 5 sticks on the table.
  • there's one and only one stick you can remove.
  • sticks are recognizable : there aren't overlapping sticks on the same orientation and there aren't sticks joined which form a longer line.
  • input should be not ambiguous, there should be only one valid solution as pointed out by @Arnauld comment, for example this input is not valid
  • Trailing /leading spaces doesn't matter.

Sticks are 4 chars long and are placed vertically or horizontally.

 | ————
 |
 | 
 |

Test cases [Before, after]

[" 
 ||| 
 —|—— 
 ||| 
 |||— 
 ",
" 
 | | 
 ———— 
 | | 
 |—|— 
 "],
[" 
 ||| 
 —|—— 
 ||| 
 |||—— 
 
 ",
" 
 | | 
 ———— 
 | | 
 |—|—— 
 
 "],
[" 
 ||| 
 —|—— 
 ||| 
 |||——— 
 
 ",
" 
 | | 
 ———— 
 | | 
 | |——— 
 
 "],
[" 
 | 
 ———| 
 |——— 
 | | 
 |———— 
 ",
" 
 | 
 ———| 
 |——— 
 | | 
 | 
 "],
[" 
 | 
 | 
 | 
 ———— 
 | | 
 | | 
 |——— 
 | 
 ",
" 
 | 
 | 
 | 
 || 
 | | 
 | | 
 |——— 
 | 
 "],
[" 
 
 | 
 ———— 
 ——|— 
 |——— 
 | 
 
 
 ",
" 
 
 | 
 | | 
 ——|— 
 |——— 
 | 
 
 
 "],
[" 
 
 | | 
 ————| 
 | |——— 
 | | | 
 | 
 
 ",
" 
 
 | | 
 | | | 
 | |——— 
 | | | 
 | 
 
 "],
[" 
 
 ———| 
 ——|— 
 —|—— 
 |——— 
 
 
 ",
" 
 
 ———— 
 ———— 
 ———— 
 ———— 
 
 
 "],
[" 
 | 
 —||— 
 || 
 ———— 
 | | 
 | 
 | 
 ",
" 
 | 
 —||— 
 || 
 ||| 
 | | 
 | 
 | 
 "],
[" 
 
 |——— | 
 | | | 
 | | | 
 ———| | 
 
 ",
" 
 
 |——— 
 | | 
 | | 
 ———| 
 
 "]

Input specifications
You can add trailing and leading whitespaces / lines as your wish, , I hope this can help focusing on the task by avoiding data bounds checking.

here is a small program to get input data in some formatting. In the header section you can change some characters like array bounds and others.
Data is in the form of a square matrix and the image is surrounded by whitespaces.

Rules

  • Input/output can be given by any convenient method.
  • You can print it to STDOUT, return it as a function result or error message/s.
  • Either a full program or a function are acceptable.
  • Standard loopholes are forbidden.
  • This is so all usual golfing rules apply, and the shortest code (in bytes) wins.

Sandbox

asked Jan 24, 2022 at 16:57
\$\endgroup\$
0

1 Answer 1

4
\$\begingroup\$

Charcoal, 102 bytes

×ばつ§-|¬η4F4↓§ -⊙EErlKDχ✳κ...κ⌕Eκ›μ 0∧›5LκNoκ-¿η‖T↗

Try it online! Link is to verbose version of code. Takes input as a list of strings containing spaces, minus signs or pipes. Explanation:

WS⊞υι

Input the game.

υ

Output the game to the canvas.

×ばつ-4η≔Σηζ

Try to locate a horizontal stick.

¿η

If one was found, then...

‖T↗

... reflect the canvas transforming between minus signs and pipes, ...

«

Otherwise, ...

≔Eθ⭆υ§λκυ

... transpose the game array (sadly without transforming), ...

×ばつ|4ζ

... and find a vertical stick.

×ばつ§-|¬η4

Jump to the stick's current location on the canvas.

F4↓§ -⊙EErlKDχ✳κ...κ⌕Eκ›μ 0∧›5LκNoκ-

Overwrite the pipes of the (possibly transformed) stick with spaces, unless there are at most four consecutive non-blank characters (including the pipe itself) including at least one minus sign on at least one side of the pipe, in which case overwrite with a minus sign instead.

¿η‖T↗

Transform the canvas back if necessary before it's implicitly printed.

answered Jan 24, 2022 at 23:51
\$\endgroup\$
4
  • 2
    \$\begingroup\$ Fail it turns into a 5 char long stick \$\endgroup\$ Commented Jan 25, 2022 at 2:04
  • \$\begingroup\$ @l4m2 Thanks; I've implemented a completely different algorithm now. \$\endgroup\$ Commented Jan 25, 2022 at 11:46
  • 1
    \$\begingroup\$ I want try this testcase, but I don't know how to make it work. Should I padding some more spaces around? \$\endgroup\$ Commented Jan 26, 2022 at 2:22
  • \$\begingroup\$ @tsh Sorry, I got bit by Charcoal behaviour. It's very difficult to use if because the else is implicit (verbose mode lets you drop the else but it's still there really) so if I don't want an else then I use a for loop instead, but then that reallocates the implicit for variables... anyway, should be fixed now. \$\endgroup\$ Commented Jan 26, 2022 at 8:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.