hussam
This is what I have:
let us say the population in 2014 is 72 billion and it increases by 70 million a year. Right now, 60 million people have blue hats. If I gave every year half the increase in population blue hats (that is an increase of 35 million blue hats a year), which year will almost half the planet have blue hats? :) (49.99%)
I tried making a libreoffice spreadsheet and after 27000 rows, apparently, 48.9% of the planet have blue hats. the increase is almost negligible at this stage so making more rows is useless.
I tried goal seeker but it failed.
Any easier way to compute this?
rolf
There are so many things wrong with this.
rolf
I'm impressed by how stable LibreOffice is, to be able to reach 48%.
If I understand your formula, with x the number of years needed, the result of the equation is x = infinity. Or if you want to reach 49.99%, it's just going to be a very big number.
You have to relate 0.01% (50-49.99) to the initial population of the world (72 billion) minus those who already had a hat (60 million).
Another thing which is wrong is considering population growth as a linear increase. It's not, it's exponential.
rolf
Have you been smoking something?
Johnaudi
Never?
Since you're giving half the increase no hats, and the other half just one half. It will never catch up.
Correct me if I'm wrong, but I do not think that there is a possible way unless he gives more blue hats. In that case, what you can do is use this code: (I added another million for the blue hats, to give a solution to the problem)
long population_now = 72000000000, population_bluehats = 60000000;
int year_now = 2014;
while ((population_now / 2) > population_bluehats)
{
population_now += 70000000;
population_bluehats += 36000000;
year_now++;
} Console.WriteLine("Year: " + year_now);
Console.WriteLine("Total population: " + population_now);
Console.WriteLine("Population with Blue Hats: " + population_bluehats);
// Year 37954 in this case, but in yours, it's #inf
hussam
that's why I said almost :)
no, not smoking anything just bored ;)
rolf
Let y1 be the initial year, and y2 be the year where 49.99% of the population have blue hats.
When you will reach y2, then the 0.01 remaining % will be comprised of those people who originally had no blue hat + all the new people who have no blue hat, that is (y2-y1)x35mil.
If you can calculate the number of new people who have no blue hat, or those who have a blue hat on y2, then you can find out y2 by dividing this number by the 35million to get the number of years between y1 and y2.
I think an algebraic equation can be built from all this. I'm a bit lazy to do it myself, though.
rolf
Here's a quick JavaScript code to find the answer (can be pasted in your browser console; [F12]):
var now = {
year : 2014,
totalPop : 72000000000,
totalBlueHats : 60000000
};
function addYear(now) {
now.year ++;
now.totalPop += 70000000;
now.totalBlueHats += 35000000;
}
while((now.totalBlueHats / now.totalPop)<.4999) {
addYear(now);
}
console.log(now);
Froze my browser for a handful of seconds, but here was the result:
Object { year=5135272, totalPop=359400060000000, totalBlueHats=179664090000000}
rolf
As for the equation:
Let y1 be the initial year, y2 the target year, y1p the total pop. at y1, y1b the bluehat population at y1, y1n the non-bluehat pop at y1, etc.
y1 = 2014
m = 1000000
y2-y1 = (y2b - y1b) / 35m
y2-y1 = (y2p - y1p) / 35m
y1p = y1b + y1n
y2p = y2b + y2n
y2b / y2p = 0.4999
y1p = 72000m
y1b = 60m
Can anyone come up with an equation?
InVader
Bn = Blue hats population after n years
Tn = Total population after n years
Bn=60E6 + 35E6 x n
Tn=72E9 + 70E6 x n
Ratio=Bn/Tn
=(60 + 35n)/(72000+70n)
n=(72000xRatio-60)/35/(1-2xRatio) <- correction
Ratio=0.4999 -> n = ~5,133,257 years
Of course the 50% mark will never be reached.
Now you can try a variation of this exercise by using red hats instead of blue ones :)
Edit: Added the dropped Ratio at the indicated point
rolf
Hi InVader. Thanks for the solution. I haven't understood everything that happens in it, but most of it.
But I'm wondering why our results differ. Mine is more like 5 million years, yours is 10 million.
InVader
To start with, I have corrected my previous post, and the result is ~5,133,257 years.
The derivation is actually straight forward. It relies on the fact that every n years, blue hats will increase by 35 millions and the total by 70 millions.
Now:
Blue hats = 60,000,000 = 6E6
Total = 72,000,000,000 = 70E9
In n years, the increase will be:
Delta Blue hats: 35,000,000 x n
Delta Total: 70,000,000 x n
and the ratio will be:
Ratio = (60,000,000 + 35,000,000n)/(72,000,000,000 + 70,000,000n)
=(60 + 35n)/(72,000+70n)
Now get n in terms of Ratio:
n=(72000xRatio-60)/35/(1-2xRatio)
and do the math.
I haven't read your code to ascertain, but your slightly different answer may stem from not considering the initial 60 million blue hats.
rolf
InVader wrote
I haven't read your code to ascertain, but your slightly different answer may stem from not considering the initial 60 million blue hats.
I did consider them. Check out the first lines of the program, this is the state at the initial year.
My result - 5,135,272 - is the year when .4999 ratio is reached, not the number of years needed, n.
n is 5135272 - 2014 = 5133258 which is, er, much closer to your result :)
InVader
We have then almost the same number.
My result is actually 5,133,257.14285 and hence ~5,133,257. But to be strictly correct (using integer years only), it should be rounded up to 5,133,258 which is your answer :)
rolf
Yep, it's due to a different procedure. My program stops as soon as .4555 is reached (so it's probably a little above that ratio). It would not stop at year ...257 because by then .4555 is not reached yet.
By the way I read your equation, and it's clearer now, thanks!
There is something I'm scratching my head on, though, it's how you get from this
Ratio = (60,000,000 + 35,000,000n)/(72,000,000,000 + 70,000,000n)
=(60 + 35n)/(72,000+70n)
To this
Now get n in terms of Ratio:
n=(72000xRatio-60)/35/(1-2xRatio)
and do the math.
Adnan
Here's my code but I've been waiting around 7 minutes for the solution and it's still working. I'm trying to find a way to get rid of this While Loop, just wanted to join in with an early piece of code (that will probably never solve it quickly).
#!/usr/bin/python
#Population part
population_in_2014=72000000000
population_each_year=population_in_2014+70000000
#Hats part
hats_in_2014=60000000
hats_in_yearX=hats_in_2014+35000000
#percentage part
def percentage_of_hats(x):
popluation = population_in_2014+((x-2014)*70000000)
hats = hats_in_2014+((x-2014)*35000000)
print 100.0*hats/population #percentage
x=2015 #year to start with
while True:
x=x+1
percentage_of_hats(x)
if percentage_of_hats(x)>49.99:
print x
break
rolf
I was just reading about the speed of various languages which can be used for web apps, namely Ruby, Lua, Python, JavaScript, PHP, and I remember Python being somewhat slow (Ruby as well). PHP should be average, JavaScript and Lua the fastest.
Also your percentage_of_hats seems to be unnecessarily complicated. I'm not sure why. Did you take a look at my JavaScript code? All what it does for every while loop, is 3 additions and one division. That's all that's needed.
Yours does 2 additions, 2 substractions, 3 multiplications and one division for every loop, then a call to print, which is probably the slowest of all these operations.
And do I see a redundant call to percentage_of_hats() in the while loop? If that's true, then multiply all of the above by two.
Adnan
rolf wroteI was just reading about the speed of various languages which can be used for web apps, namely Ruby, Lua, Python, JavaScript, PHP, and I remember Python being somewhat slow (Ruby as well). PHP should be average, JavaScript and Lua the fastest.
Also your percentage_of_hats seems to be unnecessarily complicated. I'm not sure why. Did you take a look at my JavaScript code? All what it does for every while loop, is 3 additions and one division. That's all that's needed.
Yours does 2 additions, 2 substractions, 3 multiplications and one division for every loop, then a call to print, which is probably the slowest of all these operations.
And do I see a redundant call to percentage_of_hats() in the while loop? If that's true, then multiply all of the above by two.
I tried not to look at your code to try it myself. Anyway, I guess mine is too complicated so let's ditch it.
Now isn't this a copycat of your Javascript code ?
#!/usr/bin/python
population_now=72000000000
hats_now=60000000
current_year=2014
while hats_now / population_now<.4999:
current_year+=1
print current_year
It still does take a long time :/
EDIT : I guess I didn't understand the "now.year ++" part, what does it mean ?
InVader
rolf wrote
There is something I'm scratching my head on, though, it's how you get from this
Ratio = (60,000,000 + 35,000,000n)/(72,000,000,000 + 70,000,000n)
=(60 + 35n)/(72,000+70n)
To this
Now get n in terms of Ratio:
n=(72000xRatio-60)/35/(1-2xRatio)
R = (60 + 35n)/(72,000+70n)
(72,000+70n)R = 60 + 35n
72,000R+70nR = 60 + 35n
60 + 35n = 72,000R+70nR
35n - 70nR = 72,000R - 60
(35 - 70R)n = 72,000R - 60
n = (72,000R - 60)/(35 - 70R)
n = (72,000R - 60)/(35 x (1-2R))
n = (72,000R - 60)/35/(1-2R))
InVader
A Pascal program took less than a second to output 5133258!
program Project1;
var
B, T, N: Int64;
P: double;
begin
B := 60000000;
T := 72000000000;
N := 0;
repeat
N := N + 1;
B := B + 35000000;
T := T + 70000000;
P := B/T;
until p >= 0.4999;
writeln(n);
end.