You are on page 1of 2

First I realised that there was a recursive nature to the maximum N number of peers for a given M

number of urinals. If M>5 then the third peer will go into the middle urinal. This means that the
larger problem can be split up into two smaller problems on either side of the middle peer. For
instance if there are 7 urinals the third peer will go into the middle (4th urinal) so that it looks like
this:

X--X--X

He splits it up into two problems with 4 urinals:

X - - X and X - - X

Although he is included in both problems so you have to remove 1.

If M is odd then the maximum number of peers that can be fit in N(M) is N(M)=2* N((M+1)/2)-1.

If M is even then the middle peer splits the problem into two uneven smaller problems. e.g. with 8
peeers below:

X--X---X

So if M is even N(M)=N(M/2) + N(M/2 + 1) -1.

You can apply this formula to graph the the maximum number of peeers for each number of urinals:

Maximum number of peeers for a given number


of urinal
120

100
Number of peeers

80

60

40

20

0
1
10
19
28
37
46
55
64
73
82
91
100
109
118
127
136
145
154
163
172
181
190
199
208
217
226

Number of urinals
You can then with this data find the minimum number of urinals for a given number of peers:

Minimum urinals needed for a given number of


peers
140

120

100

80

60

40

20

0
1 3 5 7 9 11131517192123252729313335373941434547495153555759616365

Looking at the graph I then noticed the pattern described in the solution.

You might also like