Adnan wrote
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 :/
It is going to take forever, because although it looks like a copycat, there is something missing: you should increase population_now and hats_now in every while loop. Right now you're just increasing the year, which means that the test (hats_now / population_now<.4999) will always return true, since hats_now and population_now don't change, so the loop will run forever!
Don't worry about writing a "copycat", not to brag, but this is a relatively simple problem, so if you want to solve it programmatically and in the most simple way, you'll most probably end up with something close to what I wrote.
Adnan wrote
EDIT : I guess I didn't understand the "now.year ++" part, what does it mean ?
++ is just a short-hand for += 1. I don't know if it's available in Python.
InVader wrote
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))
Thanks :)
Got it now. My algebra skills are a little rusty, so thanks for that.