Re: while-question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2008-11-17 at 19:07 +0100, Jochem Maas wrote:
> Robert Cummings schreef:
> > On Mon, 2008-11-17 at 14:54 +0000, Stut wrote:
> >> On 17 Nov 2008, at 14:31, Nathan Rixham wrote:
> >>> if you really want a challenge try this one..
> >>>
> >>> task: add the numbers 5 and 17 together, using php, without using  
> >>> the + operator. fill it in:
> >>>
> >>> function add($a , $b) {
> >>> //code here but no + - / * operators
> >>> return $answer;
> >>> }
> >>>
> >>> echo add(5, 17);
> >> Elemental my dear Mr Rixham...
> > 
> > What level is that elemental?
> 
> well it's all bitwise operating ... can't get much more
> elemental that a bit in CS. but I think he meant to
> say elementary (assuming the Sherlocks Holmes catchphrase)
> 
> > 
> >> function add($a , $b)
> >> {
> >>    $answer = $a ^ $b;
> >>    while (0 != ($a & $b))
> >>    {
> >>      $b = ($a & $b) << 1;
> >>      $answer = $answer ^ $b;
> >>    }
> >>    return $answer;
> >> }
> 
> nice, I think :P
> 
> > He only said you couldn't use the + operator... nothing was said about
> > using the - operator.
> 
> <quote>
> //code here but no + - / * operators
> </quote>

Oh... duh! :) You know what they say, if you're going to say something,
say it all in one place, not part of something in one place, and the
rest later on. Not everyone reads to the end you insensitive clod ;)

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux