1. Re: brain gymnastics (SPOILER!)
- Posted by "Carl R. White" <cyrek at BIGFOOT.COM> Jun 01, 2000
- 434 views
On Thu, 1 Jun 2000 08:38:31 +0000, Tor Gausen <tor.gausen at C2I.NET> wrote: > Check out this perfectly legal (promise!) Euphoria > program, what value do you suppose will be printed? > > integer i > > i = 1 > > i = -i > > i /= i+1 > > +i = +i > > i *= i-1 > > -i = -i > > ? i ROFL! I like it! Deliberate bad formatting => confusing code. With sensible formatting the code becomes: integer i i = 1 --> i = 1 i = -i --> i = -1 i /= ((i + 1 + i) = +i) --> i /= (((-1) + 1 + (-1)) = +(-1)) --> i /= ((0 - 1) = -1) --> i /= (-1 = -1) --> i /= 1 --> i = -1 / 1 --> i = -1 i *= ((i - 1 - i) = -i) --> i *= (((-1) - 1 - (-1)) = -(-1)) --> i *= ((-2 + 1) = 1) --> i *= ( -1 = 1) --> i *= 0 --> i = 0 ? i -- prints '0' Where the heck did you find this nightmare?! It's worse than the sequence mungers I come up with! Carl -- Cheered up for the day. -- No carrier. Use paper bag instead (Y/n)?