Cleaning the dishes
In this task, you will be given a bar of soap with a width of 1 or more units. You will also be given a plate, which you will have to clean, using the soap as few times as you can. The plate will be at least 1 character. You will have to output a plate with the 'clean' character representing the plate, and a third unique character to represent in what positions the bar of soap was placed.
How much the soap cleans:
(n-1)//2 on each side for odd n
(n-1)//2 on the left side of the soap bar for even n
n//2 on the right side of the soap bar for even n
Note: n//2
means floor(n/2)
.
Input
An integer greater than or equal to 1. A series of 2 unique characters to represent clean portions and dirty portions. Here, '=' represents a dirty portion, and '-' represents a clean portion. '+' represents where the soap was placed. Before the colon is what is the input, and after the colon is what is outputted.
IN : OUT
3 ===- : -+--
32 ================================ : ---------------+----------------
1 ==== : ++++
5 ----- : -----
4 -====- : --+---
3 -====- : --+-+-
7 === : +--
6 - : -
6 -==-===- : ---+----
5 -==--==- : ---+--+-
3 -==--==- : --+--+--
Rules
- There are multiple solutions. Any one of them are acceptable, as long as they use the soap the minimum amount of times possible.
- This is a code-golf contest, so the shortest answer in bytes wins!
- Input may be whatever you want, as long as the plate and soap are specified, and clean/dirty portions of the plate are different. For example, strings and arrays of integers are allowed.
- Output is of your choosing. You just need to make sure clean and soap portions of the output plate are different, but consistent. The plate and where the soap was placed should be shown.
- Standard loopholes are not allowed.
Sandbox: Sandbox for Proposed Challenges
n//2
meanfloor(n/2)
? If it does, we would have \$0\$ on both sides for \$n=3\$, which would invalidate the 1st test case. So I guess you probably mean something else. \$\endgroup\$n//2-1
should be(n-1) // 2
. \$\endgroup\$