The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

I was given a challenge for Perl; by caffine-iv2003-01-19 02:34:14
  How about this ? by Yaeger2003-01-19 04:49:15
    well.. by Gorash 2003-01-19 05:00:43
This is a more "human" way of solving the problem...
By yourself you would just say:
Well, A=123 and B=456, so swapped its A=456 and B=123, wheres the problem...

However, if you implement your solution in a computer program, it would be something like
a := a + b - a; { old pascal style... }
b := a + b - b;
because you dont want to store a+b in an extra variable.

If the computer computes this with a=123 and b=456 he will end up with:
a := 123 + 456 - 123 = 456;
after this is a = 456!
b := 456 + 456 - 456 = 456;
and the swapping failed...

Dont forget, a cpu itself cant remember anything, its dumb as a brick (of copper/aluminium/etc...)
If you want to realize the problem the way it occurs to the computer, just increase the amount of data insanely.
Please swap an array of... lets say... 2 mio integers by looking on it...

I hope this helped you
[ Reply ]
      Ehm.... by Yaeger2003-01-19 05:16:35

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)