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
  Interesting... by Spazmatic 2003-01-19 09:40:41
I believe several people are on the right track with answers such as
a = a + b;
b = a - b;
a = a - b; (Yaeger)

and Stavros' XOR equivalent, namely in that the key (if such an answer is possible) is that we can use one of the two variables to store the information for both (if they are integers). In fact, I think Yaeger's solution does work for integers (though I'm probably just missing something).

The alternative considers that it was never specified that your swap had to be built for a specific ISA. Before computer engineers realized that simple is faster, I seem to recall ISAs that included a 1-cycle swap (though I'm not sure right now). You could check that out for a nice, hacky solution.
[ Reply ]
    Stavros' XOR solution doesn't risk overflows by kahuana2003-01-19 09:52:32
      Overflow isn't really a problem. by Beorn2003-01-19 11:37:40

 

[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.)