# 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