Re: brain gymnastics
On Sun, 4 Jun 2000 15:10:33 +0200, Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL>
wrote:
>> > integer i
>> > i =3D 1
>> > i =3D -i
>> > i /=3D i+1 [note a]
>> > +i =3D +i [note b]
>> > i *=3D i-1 [note c]
>> > -i =3D -i
>> > ? i
>
>integer i
>i =3D 1
>i =3D -1
>i =3D i / ( i + 1 + ( i =3D +i ) )
>i =3D i * ( ( i -1 ) - (i =3D -i) )
>? i
>
>Does precize the same.
Run the two programs as they stand, Ralf. Yours returns '2'. The first
returns '0'...
I made the same mistake right after I'd figured out the linebreak trick...
I've noticed those who have tried to solve Tor's problem have all been
doing the same thing:
There's a tendency to see (things like):
a *=3D a + b + c =3D d
-- Uh-oh.
...as:
a =3D a * (a + b + (c =3D d))
-- Multiply 'a' by (a + b) if c !=3D d, and (a + b + 1) if c =3D d.
...when we should be reading it as:
a =3D a * ((a + b + c) =3D d)
-- Make 'a' zero if (a + b + c) =3D d, leave it alone otherwise.
Yet in situations like this:
if a + b + c =3D d then...
...we know exactly what the expression means!
I reckon that this is some kind of "codical" illusion, and also a darn good
argument for using parentheses to make expressions more readable.
Carl
--
Insert clich=E9 about inserting witty comment here, here.
|
Not Categorized, Please Help
|
|