Of course, the SE network is very knowledgeable about how to be respectful in the restroom, but for those of you who need a recap, being respectful means flushing the toilet, etc. Most importantly, though, it means using the stall as far away from others as possible.
Given a blueprint of a set of stalls with indications of which ones are in use as a string, you must return or print from a function or program where the most respectful place to do your business is.
0 1 2 3 4 5 <- The stall number which is not actually visible in the input. | | |-| |-|-| <- the stalls
The stalls are numbered in ascending order from left to right. There will always be at least one empty stall. There can be up to 50 stalls in an input. You can also take the input as an array or string of
1s or booleans if you prefer to do so.
Stalls in use have
- in them (in between the pipes).
The most respectful stall to go to is the one that is on average farthest away from the ones in use. The distance between two stalls is the absolute value of the difference of the numbers above them.
Just to be clear: you are finding the average distance from all of the stalls—not just the neighboring ones.
You must output the lowest number of the most respectful stall to go to that is empty.
Input: |-| |-| OR 101 Output: 1 Input: | | |-| |-|-| OR 001011 Output: 0 Input: |-| |-| | | | |-|-| OR 101000011 Output: 1 Input: |-| | | | | |-|-| | | | | OR 100000110000 Output: 11 Input: |-|-|-|-| | | | | | |-| OR 11110000001 Output: 9 Input: |-| | OR 10 Output: 1 Input: |-| | |-| OR 1001 Output: 1
This is code-golf, so shortest code in bytes wins!
You can use 0 or 1 based indexing in your answer — whichever you prefer; if you use 1 based indexing, then you must say so explicitly in your answer.