I think this program will work under the condition that the fault one is
heavier in weight, but the case is that it may be "lighter" OR "heavier".

Ok enough of php interview questions.
I need to pass a value to a function in .js file which has been linked in a
php file which in turn has been included in another php file.

------------------
//main.php
fetch DB values and store it in $param.
include"first.php"
------------------->

-------------------
//first.php
<script language='JavaScript' src='/myjs.js'>
</script>
------------------->

-------------------
myjs.js
function fun(param)
{
... process with param
}
------------------->

How can I achieve this?

-murugesan

----- Original Message -----
> Binary search.  I'd say I have too much time on my hands, but I don't.
>
> <?php
>
> $eggs = array(1,1,1,1,1,2,1,1,1,1,1,1);
>
> $eggs1_6 = array_slice($eggs, 0, 6);
> $eggs7_12 = array_slice($eggs, 6, 6);
>
> if (array_sum($eggs1_6) > array_sum($eggs7_12))/////////// First time
> $half_eggs = $eggs1_6;
> else
> $half_eggs = $eggs7_12;
>
> $eggs1_3 = array_slice($half_eggs, 0, 3);
> $eggs4_6 = array_slice($half_eggs, 3, 3);
>
> if (array_sum($eggs1_3) > array_sum($eggs4_6))///////////Second time
> $quarter_eggs = $eggs1_3;
> else
> $quarter_eggs = $eggs4_6;
>
> if ($quarter_eggs[0] == $quarter_eggs[1])///////////Third time
> $egg = $quarter_eggs[2];
> else if ($quarter_eggs[0] > $quarter_eggs[1])
> $egg = $quarter_eggs[0];
> else
> $egg = $quarter_eggs[1];
>
> $index = array_search($egg, $eggs) + 1;
>
> print "Heavy egg is egg number {$index}\n";
>
> ?>
>
> murugesan wrote:
>
> > In a group of 12 eggs only one is having weight less or more.
> > Can we have a program to find the egg, provided we have to weigh only
three
> > times with a weighing machine with two pans,without using weights.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to