• Coding
  • this randomly crossed my mind

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.
public class blueHats {
        public static void main(String[] args){
                int year = 2014;
                double pop = 72000000000.0;
                double blue= 60000000.0;
                double coef = blue/pop;
                while(coef < 0.4999){
                        year++;
                        pop =pop + 70000000.0;
                        blue= blue + 35000000.0;
                        coef = blue/pop;
                }
                System.out.println(year);
        }
}
the year is 5135272

i also tried to solve it mathematically and came up with this
(pop is the current population which is 72 billion, blue is the number of people who currently have blue hats 60 million, inc is the yearly increas which is 70 million)
rolf wrote
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.
Ah, that was stupid. It takes around 9s to solve it now.
I wonder if Hussam was wearing a blue hat or a red one while this randomly crossed his mind :)
InVader wroteI wonder if Hussam was wearing a blue hat or a red one while this randomly crossed his mind :)
Blue. It's my favorite color ;)
i havent read all codes and posts.
put proofing that b/p=0.5 will lead to 0=0
as rolf said that small difference between 0.5 and 0.49 which was later used to divide a number and thus make it bigger is very important.
in fact, im still not convinced we can study such tendancies without limits, the difference to be used is theoric epsilon and not 0.1. it still works however if you want numbers and just numbers.
i will sum it up and add that a negligeable 0.0000001 difference will add thousands maybe millions of years. but as hussam suggested using 0.49, just for fun :D
this is the analysis of the equation:
r=(60+35n)/(72000+70n) using invader notations (n=years ; r=ratio)
n=(r72000-60)/(35-70r)
lim(r-> 0.5, n)= lim(r->0.5, (r72000-60)/(35-70r))=(0.5*72000-60)/(0-0)=+inf or =((0.5-e)*72000-60)/(35-70(0.5-e) where e is 0+ or epsilon, like 0.0000...1