RE: [PHP] while-question
| From: | bruce | Date: | Mon, 17 Nov 2008 18:00:10 +0000 |
| Subject: | RE: [PHP] while-question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-283380@lists.php.net to get a copy of this message | ||
curious qiestion....
to all on here who dabble in php... how many of you have actully gone to
college, taken algorithm courses, microprocessor courses,
design/architecture courses, etc..
or is the majority of the work here from people who've grabbed the tools and
started programming... ?
-----Original Message-----
From: Robert Cummings [mailto:robert@interjinn.com]
Sent: Monday, November 17, 2008 9:53 AM
To: Stut
Cc: Nathan Rixham; php-general@lists.php.net
Subject: Re: [PHP] while-question
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?
> function add($a , $b)
> {
> $answer = $a ^ $b;
> while (0 != ($a & $b))
> {
> $b = ($a & $b) << 1;
> $answer = $answer ^ $b;
> }
> return $answer;
> }
He only said you couldn't use the + operator... nothing was said about
using the - operator.
$total = -(-5 - 17);
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