Exclusive Or

Discussion of challenges you have already solved
lukas
Posts: 34
Joined: Wed Nov 26, 2008 1:53 pm
Location: Germany

Exclusive Or

Post 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
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Re: Exclusive Or

Post by m!nus »

wow, that's your code! and now?

p.s. mine is 15 instructions shorter that yours
theStack
Posts: 72
Joined: Sun Nov 02, 2008 12:46 am

Post 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.
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Post by m!nus »

Well, I mean, a short comment would be nice, only posting code is a bit pointless.
homeas
Posts: 10
Joined: Thu Nov 13, 2008 11:17 pm

Post 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
tails
Posts: 191
Joined: Tue Jun 10, 2008 7:51 pm
Location: Tokyo

Post 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.
the_impaler
Posts: 61
Joined: Wed Apr 30, 2008 3:31 am

Post 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:
gfoot
Posts: 269
Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK

Post by gfoot »

the_impaler wrote:Hacker works alone.
I totally disagree with this sentiment, but I don't really want to argue about it.
tog
Posts: 70
Joined: Fri Nov 14, 2008 11:23 am
Location: Germany

Post 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.
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Post 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
tog
Posts: 70
Joined: Fri Nov 14, 2008 11:23 am
Location: Germany

Post 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: ).
brazzy
Posts: 14
Joined: Fri Nov 07, 2008 2:30 am
Location: Munich, Germany
Contact:

Post 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.
macdachs
Posts: 6
Joined: Tue Oct 28, 2008 6:54 pm

Post 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.
megabreit
Posts: 141
Joined: Sat Jan 03, 2009 3:33 pm

Post 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!
BieneMaya
Posts: 4
Joined: Sat Apr 25, 2009 9:37 pm

Post 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

Post Reply