3 ms·
Took me about 20 minutes to solve using a bruteforce solution scaling linearly over the total revenue (in cents, so in this case 10500 iterations). Writing dow
by nightcracker 12y ago
Took me about 20 minutes to solve using a bruteforce solution scaling linearly over the total revenue (in cents, so in this case 10500 iterations).
Writing down equations:
x*a + (10 - x)*b = 3500
y*a + (16 - y)*b = 3500
z*a + (26 - z)*b = 3500
x*a + (10 - x)*b + y*a + (16 - y)*b + z*a + (26 - z)*b = 3 * 3500
(x + y + z)*a + (10 - x + 16 - y + 26 - z)*b = 10500
(x + y + z)*a + (52 - (x + y + z))*b = 10500
p = x + y + z
p*a + (52 - p)*b = 10500
a = (10500 - (52 - p)*b) / p
p is the total number of chickens sold before the break. Obviously this can't be negative nor more than 52.
At least 1 chicken must be sold both before and after the break, because 52 is not a factor of 10500.
So 0 < p < 52.
We know that b < a so b < (10500 - (52 - p) * b) / p.
b < (10500 - (52 - p)*b) / p
b*p < 10500 - (52 - p)*b
b*p + (52 - p)*b < 10500
b*52 < 10500
b < 202
This is easy to bruteforce:
for p in range(1, 52):
for b in range(1, 202):
if (10500 - (52 - p)*b) % p == 0:
a = (10500 - (52 - p)*b) // p
if ((3500 - 10*b) % (a - b) == 0
and (3500 - 16*b) % (a - b) == 0
and (3500 - 26*b) % (a - b) == 0):
x = (3500 - 10*b) // (a - b)
y = (3500 - 16*b) // (a - b)
z = (3500 - 26*b) // (a - b)
if 0 <= x <= 10 and 0 <= y <= 16 and 0 <= z <= 26:
print("Before the break one chicken cost ${:.2f} and the farmers sold ({}, {}, {}).".format(a / 100, x, y, z))
print("After the break one chicken cost ${:.2f} and the farmers sold ({}, {}, {}).".format(b / 100, 10-x, 16-y, 26-z))
Spoiler:
Before the break one chicken cost $3.75 and the farmers sold (9, 6, 1).
After the break one chicken cost $1.25 and the farmers sold (1, 10, 25).