Circumstances notwithstanding, gentlemen prefer not to stand next to other gentlemen at the urinal. If the row is long enough it's all about personal space. The holy grail of urinal usage is to identify an empty stall between two other empty stalls... and unzip, and breathe out.
But how many gentlemen can stand at a urinal before someone has to stand next to someone else?
On the face of it this is a simple question. Take a row of 7, for example.
1
2
3
4
Here every alternate stall is filled, everyone's privacy is assured and the maths is simple. The number of gentlemen accommodated is half the number of stalls, rounded up.
But gentlemen are not simple. In particular when they approach a urinal they're not thinking about setting up the optimum spacing, they just want to keep as far away from everyone else as possible. This can result in a wholly inefficient use of facilities, and before you know where you are a queue has started.
What really happens with a row of 7 is this.
Gentleman 1 takes the end stall.
1
Gentleman 2 goes right down the far end.
1
2
Gentleman 3 stands in the middle, maximising his distance from the other two.
1
3
2
All the available stalls are now immediately alongside an occupied stall, so when gentleman 4 enters he has nowhere to go. Theory suggests seven stalls will fit four gentlemen comfortably, but the reality is only three.
We need some rules to model the situation.
i) The first gentleman takes the end stall.
ii) All subsequent gentlemen stand as far away from the other gentlemen as possible.
iii) As soon as all stalls are either occupied or adjacent to an occupied stall, a queue starts.
Let's look at the four simplest rows of urinals first, that's n=1, n=2, n=3 and n=4.
1
1
1
2
1
2
One stall is the most efficient layout, permitting 100% usage. The second stall is wasted because nobody wants to go there. The introduction of a third stall permits a second participant. The fourth stall is again wasted.
Next n=5, n=6 and n=7.
1
3
2
1
3
2
1
3
2
Five stalls means three gentlemen, optimally spaced. Six stalls also only allows three, and so does seven (as we saw earlier).
Next n=8 and n=9.
1
3
4
2
1
5
3
4
2
Eight stalls increases the number of gentlemen to 4 and nine stalls increases it again to 5. Nine's great because it halves well - the third gentleman goes in the middle allowing four and five to slot in either side.
It doesn't get any better.
1
4
3
5
2
1
4
3
5
2
1
5
3
4
2
1
5
3
4
2
Ten, eleven, twelve and thirteen stalls still only permit five gentlemen. More might fit if those gentlemen spaced out optimally but they don't, they act selfishly instead. If you're thinking of installing a urinal don't go for ten, eleven, twelve or thirteen stalls, stick with nine because the extra would be a waste of resources.
Here are all those numbers in a table.
n
1
2
3
4
5
6
7
8
9
10
11
12
13
U(n)
1
1
2
2
3
3
3
4
5
5
5
5
5
n is the number of stalls. U(n) is the number of gentlemen who occupy them.
I've decided to call U(n) the urinal function.
It's a very strange mathematical function because it increases erratically. Three 3s, then a single 4, then five 5s suggests there is an underlying pattern but it's nothing simple.
Here's how the urinal function continues from 14 stalls to 26.
n
14
15
16
17
18
19
20
21
22
23
24
25
26
U(n)
6
7
8
9
9
9
9
9
9
9
9
9
10
Now we have nine 9s in a row. Something quite peculiar is going on here.
Practically speaking you wouldn't install a row of urinals 25 stalls long, and even if you did gentlemen wouldn't occupy them according to these rules. But if they did then nine gentlemen would slot into those 25 stalls before a queue started.
1
6
4
8
3
7
5
9
2
25 occurs at the end of the sequence of nine 9s, the point at which all the occupied stalls have two empty spaces inbetween. 26 is more efficient because the extra stall creates a gap for a 10th person to fit into. 27 adds another, 28 another... all the way up to 33, beyond which comes a sequence of seventeen 17s.
The underlying pattern is all to do with powers of 2.
If n is a power of 2 then U(n)=½n.
n
4
5-7
8
9-13
...
16
17-25
...
32
33-49
...
64
65-97
U(n)
2
3
4
5
...
8
9
...
16
17
...
32
33
Immediately after a power of 2 comes a sequence of identical numbers.
If n is a power of 2 then it's followed by x identical x's, where x=½n+1.
For example a very long urinal with 512 stalls would provide relief for 256 gentlemen, while anything from 513 to 769 stalls would satisfy just 257.
The urinal function has an underlying rationale which is much more complicated than might be imagined from what looks to be a straight-forward problem. Something to mull over the next time you're waiting for a space in the Gents, gents.
(and if your eyes glazed over a long time back never mind, it was only a hypothetical urinal anyway)