Page 1 of 2

Exclusive Or

Posted: Fri Dec 05, 2008 12:42 pm
by lukas
my code:

Code: Select all

8888888******3>3<78*1+?0<3</0^7?0<3<-0>1<3</0^7?1<3<-1>:3?11g03<*4<+4>3<2/3>96+c4<p

Re: Exclusive Or

Posted: Fri Dec 05, 2008 1:49 pm
by m!nus
wow, that's your code! and now?

p.s. mine is 15 instructions shorter that yours

Posted: Fri Dec 05, 2008 6:32 pm
by theStack
What's so bad if anyone who has completed the challenge is posting his code, m!nus?
Absolutely no reason to be pissed 8)

Well I don't have my code here right now on this machine but I can tell you it's MUCH more longer so I have obviously done the thing way too complicated. And that's the reason why I think it's a good think to see some code of others in the "Challenges Solved" forum, because it's nice to learn something and see what I can do better in the future.
If we all think we are the best and the code of the others is shitty, posting in this part of the forum is senseless anyway.

Posted: Sat Dec 06, 2008 11:35 am
by m!nus
Well, I mean, a short comment would be nice, only posting code is a bit pointless.

Posted: Thu Dec 18, 2008 12:32 pm
by homeas
just programming it straight bit for bit with no tricks at all you get 54 instructions which is 29 instructions shorter than Lukas's code and easier to understand, but that's really nothing to get excited about -- a bit different to the tricky program for the smallest mouse with only 21 instructions ...

I have no problems to publish the xor solution here, but I don't know the policy of this forum -- so may one of the moderators may put a comment on this. I think it's better to discuss the results on "real code" than gloating about it only with instruction lengths or so.

greetings & merry christmas, homeas

Posted: Thu Dec 18, 2008 4:45 pm
by tails
Although I am not a moderator, I think it's quite good to discuss the result, including the code, and that is the role of this "Challenges Solved" forum. But, as m!nus says, just showing the code is a bit pointless.

And we must take care not to spoil other challenges. For example, we should not show the answer to the "Mod" challenge which is also valid to the "Fast Mod" challenge, in the "Mod" thread. Of course, showing it in the "Fast Mod" thread is ok. It's applicable not only to the code itself but also to the underlying thoughts and ideas of the code.

Some of us, including me, are taking better care not to spoil the possibilities of future challenges. That's why we're sometimes refering to only the length of the code.

Posted: Thu Dec 18, 2008 5:57 pm
by the_impaler
I agree with tails.
And I think we should also cherish the "hacker" term. Hacker works alone. Don't reduce it to "script kiddie". Discussing the challenges and their solutions is fine but code sharing is a bit overkill, I think. And the crowd here is probably not the one that would give you a nice "peer review" anyway. So I am second to m!nus here as well - "and you call this your code ?" :twisted:

Posted: Fri Dec 19, 2008 1:43 am
by gfoot
the_impaler wrote:Hacker works alone.
I totally disagree with this sentiment, but I don't really want to argue about it.

Posted: Fri Dec 19, 2008 7:27 am
by tog
I think careful posting and discussion of code is really valuable. The discussion with therethinker and tails in the quinine- and mighty-quine-threads is a good example .. you see other ideas and get inspiration for your own code. Meanwhile, the quinine-thread is also an example for the danger of posting code: In part, it spoils mighty-quine. But hey... mighty quine arose from this thread, so this again shows the value of discussing code.

Posted: Fri Dec 19, 2008 1:53 pm
by m!nus
gfoot wrote:
the_impaler wrote:Hacker works alone.
I totally disagree with this sentiment, but I don't really want to argue about it.
I agree with you gfoot, a hacker doesn't have to work alone, teamwork doesn't make him less of a hacker, plus if you work together with someone else you can exchange ideas that the other one maybe would have never come up with.

p.s. i wanna do quine :( but i'm too lazy to do spiral bits

Posted: Fri Dec 19, 2008 2:00 pm
by tog
m!nus wrote:i wanna do quine :( but i'm too lazy to do spiral bits
Oh, Spiral Bits is fun! Really! One of the challenges where there are many possible approaches and you can get really creative (unless you are doing it by hand :wink: ).

Posted: Fri Dec 19, 2008 11:20 pm
by brazzy
the_impaler wrote:I agree with tails.
And I think we should also cherish the "hacker" term. Hacker works alone. Don't reduce it to "script kiddie".
I disagree, violently so. Script kiddies work alone. Hackers most of all want to understand and learn, and both of those are much easier when talking to others to compare idead (and impossible without that beyond a certain point).

In a way I think it's a shame that we can't freely share solutions and algorithms with everyone here, because while the competion of finding them yourself is a great motivator, it also reduces or completely eliminates the possibility to learn from others.

Posted: Fri Apr 03, 2009 7:20 pm
by macdachs
One Question by the way,

I just solved this one (not the Easy way):

The challange gives us two Integers. Is it right, to calculate only numbers smaler than 8^7 or do i have to calc with 32 Bit?

I think with bigger numbers than 2097152 the solution of lukas wouldnt work.

Posted: Mon May 18, 2009 11:52 pm
by megabreit
Thanks to lukas for posting his code! I completely agree with theStack. No code is pointless if it solved the challenge! I'd like to see other solutions in the "Solved" forum even if there's no comment at all!
In the forum very often people say it's great to learn from the challenges. But you don't learn just by dealing with a problem... you also learn by dealing with other peoples work. Don't be greedy! Share your code (the only one exception: spoilers to another challenge)! You'll never need it in a real life environment, so why keep it secret?

Here's my code:

Code: Select all

200<0^3^/3^*-0^0<1v-0>1<0^4^/4^*-0^1<1v-1>:5?1^2/+1v2*1v0<1<+0:2?2cp
It uses the modulo code from the previous challenge, works with any positive numbers and is only limited by HackVM internal integer definition.
Obviously it's not the shortest one so I encourage again everybody to post (and discuss) their solutions!

Posted: Sat Aug 29, 2009 8:45 pm
by BieneMaya
Now I understand why nobody really likes assembler-code or stack-machines, after a little coding with HVM :D

Now my solution in three steps:
Note: M[x] is memory-cell number x, with x element of integer

Code: Select all

A)

0: move 1 to M[2] /* in M[2] is used as counter */
1: while (a != 0 || b != 0) {
	2.0: if (a % 2 != b % 2) {
		2.1 M[3] += M[2] /* in M[3] the result is saved*/
	}
	3.0: a /= 2 
	3.1: b /= 2 
	3.2: M[2] *= 2
}
4: print M[3]

B)

0: 12>
1: 0<0:(Quantity_Instructions_until_4)? 0<1:(Quantity_Instructions_until_2.0)? 1<0:(Quantity_Instructions_until_4)?
	2.0: 0<0<2/2*-1<1<2/2*-:(Quantity_Instructions_until_3.0)?
		2.1 3<2<+3>
	3.0: 0<2/0>
	3.1: 1<2/1>
	3.2: 2<2*2>
	3.3: (Negative_Quantity_Instructions_until_1)g /* this is necessary to replace while in number A) 1: */
4: 3<p

C)

12>0<0:89*0d?0<1:25*?1<0:69*0d?0<0<2/2*-1<1<2/2*-:7?3<2<+3>0<2/0>1<2/1>2<2*2>099*1+-g3<p