Staredit Network > Forums > Null > Topic: Riddle
Riddle
Oct 17 2011, 7:21 pm
By: Apos  

Oct 17 2011, 7:21 pm Apos Post #1

I order you to forgive yourself!

Hey all! In this thread, you can post your riddles so others can try and figure them out.

In order to start a new riddle, the previous riddles have to be solved or declared unsolvable or skipped (I guess this can be decided if no one likes the current riddle.).

Here is this first riddle. It's related to coding and programming languages.

Code
//Assuming you have two variables, 'a' and 'b'. Find a way to swap them without the need for a third variable 'c'.
int a = 4;
int b = 5;

int c = a;
a = b;
b = c;

//Here a = 5 and b = 4.


Note: I'm pretty bad at starting those kind of games so any suggestions to improve the current setup is very appreciated.

Post has been edited 1 time(s), last time on Oct 17 2011, 7:39 pm by Apos. Reason: English mistakes...




Oct 17 2011, 7:25 pm Sacrieur Post #2

Still Napping

Code
//Assuming you have two variables, 'a' and 'b'. Find a way to swap them without the need for a third variable 'c'.
int a = 4;
int b = 5;

int d = a;
a = b;
b = d;

//Here a = 5 and b = 4.


Do I get a cookie?



None.

Oct 17 2011, 7:27 pm Apos Post #3

I order you to forgive yourself!

Loled, I should have said, without adding any other variables other than 'a' and 'b'.




Oct 17 2011, 7:36 pm lil-Inferno Post #4

Just here for the pie

int a = 4;
int b = 5;

b = a + b;
a = b - a;
b = b - a;

Followed in that order you should end up with a = 5, and b = 4.




Oct 17 2011, 7:38 pm Apos Post #5

I order you to forgive yourself!

Quote from lil-Inferno
int a = 4;
int b = 5;

b = a + b;
a = b - a;
b = b - a;
:facts: First riddle solved!




Oct 17 2011, 7:38 pm ubermctastic Post #6



int a = 4;
int b = 5;

int a = a+b
int b = a-b
int a = a-b

Dangit I got ninjad



None.

Oct 17 2011, 7:43 pm Aristocrat Post #7



Why would you ever code that way...



None.

Oct 17 2011, 7:50 pm lil-Inferno Post #8

Just here for the pie

Quote from Aristocrat
Why would you ever code that way...
For the purpose of a riddle.




Oct 17 2011, 8:02 pm The Starport Post #9



Quote from Aristocrat
Why would you ever code that way...
I did things like that a lot when trying to cobble together arithmetic in starcraft triggers. :crazy:



None.

Oct 17 2011, 8:33 pm Lanthanide Post #10



Quote from Aristocrat
Why would you ever code that way...
In early/low-powered computers, they didn't have a lot of resources to spare for extra variables and such. It's doubtful that multiple arithmetic operations would ever be considered a good trade off, unless you absolutely had to do it, though.



None.

Oct 17 2011, 9:21 pm The Starport Post #11



Addition/subtraction aren't terribly expensive operations, though.



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[06:04 pm]
NudeRaider -- ihjel
ihjel shouted: "Use Display Text Message or the in-game Leaderboard to output the live values of critical Death Counters." that would be so convenient wouldn't it.
ihjel
ihjel shouted: "Use Display Text Message or the in-game Leaderboard to output the live values of critical Death Counters." that would be so convenient wouldn't it.
it's rather inconvenient actually, as it requires you to transfer it to Custom Score which might even interfere with what you're measuring. But IIRC you can also use EUDs to display it which by now could actually be somewhat convenient.
[2026-11-11. : 9:25 pm]
ihjel -- "Use Display Text Message or the in-game Leaderboard to output the live values of critical Death Counters." that would be so convenient wouldn't it.
[2026-11-11. : 6:59 pm]
Symmetry -- I just pasted what google ai told me to try to form a feedback loop
[2026-11-11. : 1:24 pm]
NudeRaider -- UndeadStar
UndeadStar shouted: https://staredit.net/topic/18961/ <= wow, if there wasn't a capital letter on almost every word in the title, and a link in the signature, I may not have guesses it's an AI bot. I don't know much about map editing, but the content may even be relevant enough to be kept.
Yeah, I've noticed it, but it raised a couple of relevant questions and kept the ad to the signature so if someone were to engage with the topic it could be a net positive which is why I kept it. We're not necessarily anti-bot, just anti-spam. Thanks to Symmetry who realized my hope. :)
[2026-11-11. : 8:09 am]
Zycorax -- Greed
[2026-11-11. : 3:25 am]
Symmetry -- why do the oligarchs want our mapping strategies???
[2026-11-11. : 3:24 am]
Symmetry -- the question is why though
[2026-11-11. : 1:10 am]
Butch -- made me feel really sad and stupid and fat
[2026-11-11. : 1:10 am]
Butch -- I got duped by one and replied and then realized after
[2026-11-10. : 11:26 pm]
Sie_Sayoka -- the turings have tested
Please log in to shout.


Members Online: GenisAlabau866, FrancBizjak388, LidiaVilaboa225, GasperRozman086, IlyaSnopchenko