# A beer problem (divide bills)

I am making an application to divide bills. I have the following problem:

Jhon and Paul were to a pub , and they consumed 20 beers. James get in the bar and they consumed ten more beers.

How much Paul have to pay ?

I tried this approach:

Jhon and Paul drank all beers so they have to pay all of them = 1

James just drink 1/3 of the beers.

So james have to pay 30/(1 + 1 + 0,33) = 30/2,33 = 12,87

I know the correct result is 13,33

What i'm doing wrong?

EDIT

I know i can calculate the price like 20/2 + 10/3. But i'm doing an algorithm and this is hard to implement that.

That's why i wanna know what i'm doing wrong.

EDIT

The correct formula is:

James drank 1/3 of the beers, but have other 2 people drank with him so, it's not 10/30 its (10 - 2,33) / 30 = 0,25

Paul have to pay 30 / (1 + 1 + 0,25)

-
How much Paul have to pay? That depends rather fundamentally on what a beer costs, which the question says nothing about. – Henning Makholm Nov 24 '12 at 12:33
@HenningMakholm this does really matter ? It's just multiply the answer for the beer price. We can assume 1$. – Guilherme Torres Castro Nov 24 '12 at 12:37 I think that after drinking 30 beers you just leave whatever cash you have in your pocket and hope not to get thrown out the next time you walk into the bar! – Asaf Karagila Nov 24 '12 at 12:41 What you are missing is that although Paul drank all the beers he drunk the first two thirds with only one guy the the rest with 2 guys. And James drank his one$\frac{1}{3}$of beers with 2 guys. So if paul drank 1 the James drunk less than$\frac{1}{3}$– clark Nov 24 '12 at 12:54 Clark, that exactly what i'm looking for,is there a way that my equation be fixed ? – Guilherme Torres Castro Nov 24 '12 at 12:58 ## 2 Answers So Paul has to pay 10 beers (20/2 because there were only Paul and John at the beginning) and "3.33" because James came there so there were Paul,John and James now and they drank 10 beers so -$10/3 = 3.33$.$10+3.33 = 13.33$For algorithm all you have to do is implement following equation in cycle, where in every step of cycle you will input new values for$b$and$n$and before cycle give$S=0$.$S = S+\frac bn\$

where

S - sum of bills
b - number of beers in one "cycle" (20 at beginning, then 10 when james came etc.)
n - number of people

-
Thanks, but i really wanna know what's wrong with my approach – Guilherme Torres Castro Nov 24 '12 at 12:44
Added more info for algorithm. – Noturab Nov 24 '12 at 12:49
Thanks Dávid, i give you a plus one. But i can only test this on monday, if this work i will mark as correct – Guilherme Torres Castro Nov 24 '12 at 13:12
You're welcome. s,b,n are real numbers when declaring. – Noturab Nov 24 '12 at 13:27

Assuming they all drank exactly the same ammount of beer that were served to them:

== Each of Jhon and Paul drank 10 + 3.333 = 13.333 beers and this each must pay.

== James drank 3.333 beers and this he pays.

-
Thanks, but i really wanna know what's wrong with my approach – Guilherme Torres Castro Nov 24 '12 at 12:45
@GuilhermeTorresCastro: Only you can answer that -- since you haven't really explained what it is, nor how on earth you could expect it to be right -- but some hints based on your single example would be that (a) it seems to produce the same answer for each of the three drinkers, (b) the "correct answer" you compare to is clearly absurd, since it has James paying for 13 beers while only 10 were consumed while he was present at all, (c) if everyone pays for 12.87 beer, there'll be money for 38.61 beers on the table at the end but only 30 were consumed (the waiter pockets the rest?) – Henning Makholm Nov 24 '12 at 12:57