King Mouse

Discussion of challenges you have already solved
theStack
Posts: 72
Joined: Sun Nov 02, 2008 12:46 am

King Mouse

Post by theStack »

Hi folks,
I just tried to figure out the solution the last few hours and finally I got it,
and believe me I was really glad that the server didn't complain, because the
algorithm is very dirty and shouldn't work!

The thing is, I break my loop when the first zero is found.
Before I counted till 20 but that just took too many instructions *grml*

So, I tried that hoping that there are no zeros in the array of numbers in the tests.
And actually, it worked ;)

For example, if there were the following numbers in the array, the algo wouldn't work:
3, 0, 876, ..........

because it would say 3 is the largest number and it would abort after seeing that there's a zero on the second place.

Here is my code:

Code: Select all

10^<0<:1+5?0^<0>1+0^<2?1c0<p
So my question, has anybody a better solution to offer? I'm just curious.
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Post by MerickOWA »

Yea, theres a better way to do this which handles zero. I'd give my solution, but I worked hard to squeeze it into the 26 instructions for "Really Small Mouse". ;)
theStack
Posts: 72
Joined: Sun Nov 02, 2008 12:46 am

Post by theStack »

Only 26 instructions? God, this seems to be impossible for me... well, that challenge will be fun 8)
I have deleted my sourcecode in the other post now because I didn't know there are more challenges
which belong to the same algorithm...

// EDIT: The edit function sucks... it doesnt't work on the first post because "Topic already exists" :roll:
sigi
Posts: 37
Joined: Sun Oct 26, 2008 4:58 pm

Post by sigi »

Exiting on "0" is cheating. I think the testing routine should be extended to capture that case (after all, the challenge does not mention that the input array does not contain zeroes).

Having said that, here's my solution which works with any input (28 instructions long, and no, I have currently no idea to make it any shorter; probably it's not possible with my approach, and the whole thing would have to be reimplemented with an added twist or two):

54*1-0^<0<:1+5?0^<0>0^2?3c<p

I hope I can solve this one day (the two follow-up challenges, I mean). I'm really, really curious how the super-short (24 ops) solution looks like, I can imagine it contains some completely-sick shortcuts.
gfoot
Posts: 269
Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK

Post by gfoot »

It's interesting to see what you guys are doing. sigi, my 28-character solution is almost identical to yours, differing only in the order of the first two characters and the mechanism of the test (I think I had the comparisons the other way around). I find it interesting that we do come up with essentially the same answer - it implies there aren't many to choose from.

I've had no luck for weeks now in thinking either of ways to reduce its size (the comparison feels long and clumsy, but all I can replace it with is similar length tests), or of alternate ways to approach it completely. I only have one real idea at the moment, but it's hard to put into practice.

I did try cheating, though, by only testing the first 9 entries, but it failed a few of the 5 tests it had to pass. I guess there's less than a 1 in 32 chance of all five tests having the actual maximum in the first 9 out of 20 entries... too much to hope for.

All that said, and interesting though it is, I wonder if discussing this here is inappropriate. adum has said in other threads that his inspiration for working out shorter versions has been from combining ideas from different people's longer solutions, and as such talking about solutions to one challenge here could reveal too much about the different approaches which, when combined, are solutions to the shorter challenges to come.
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Post by m!nus »

It's indeed very interesting, my solution is almost identical to theStack's one, just the loading part is turned around:

Code: Select all

10^<0<:1+5?0^<0>1+0^<2?1c0<p
10<1^<:1:5?0^<0>1+0^<2?1c0<p! <- mine
it may be exiting on 0, but that's not cheating, that's a fact that there comes a 0
Mütze
Posts: 23
Joined: Sun Oct 26, 2008 2:39 pm

Post by Mütze »

sigi posted my solution:-) I've only swapped the first two numbers.

Today I had some really nice ideas, but when I examined the instructions
I would have to change, I realized that the code would be longer.

It's interesting to see, that the solutions are so similar.
theStack
Posts: 72
Joined: Sun Nov 02, 2008 12:46 am

Post by theStack »

m!nus wrote:It's indeed very interesting, my solution is almost identical to theStack's one, just the loading part is turned around:

Code: Select all

10^<0<:1+5?0^<0>1+0^<2?1c0<p
10<1^<:1:5?0^<0>1+0^<2?1c0<p! <- mine
it may be exiting on 0, but that's not cheating, that's a fact that there comes a 0
Hehe, Germans and Austrians seem to think the same way when it comes to hacking :wink:

The problem here is not as much the speculation that after the numbers to sort there's a zero (well, we know that the memory is initialized with zeros, but if the server would test proberly he would put some value != 0 to mem[20]), but much more that IN the sequence of the 20 numbers there could also appear a zero! And as soon as this zero appears our code breaks the loop and the rest of the numbers will be ignored.

But well, it worked, and for "Mus Minutoides" we maybe need a completely different approach anyway.
At this time I have to admit I'm completely clueless.

Greetings from Tyrol,
theStack
the_impaler
Posts: 61
Joined: Wed Apr 30, 2008 3:31 am

Post by the_impaler »

I've got it down quite well, IMO and I am giving up on the smallest.
My solution for 28 instructions was practically like sigi/gfoot - starting from 45*1- and exiting on 0.
Mus Minutoids was not much different actually than King Mouse - try harder, guys.
I would charactirize my code like this :
King Mouse solution was nice and clean programming effort.
Mus Minutoids was more like a software project I could as a contractor written off the design specs and I would make you to sign NDA before seeing the code.
Smaller mice were like real commercial closed source product - you will always have bread on your table if you can write this code.
Zett
Posts: 3
Joined: Mon Nov 03, 2008 8:31 pm

Post by Zett »

My "Surely Smallest Mouse" needs 21 instructions 8)
the_impaler wrote: Smaller mice were like real commercial closed source product - you will always have bread on your table if you can write this code.


And yes, sometimes it generates a false answer, like closed source products :wink:
sigi
Posts: 37
Joined: Sun Oct 26, 2008 4:58 pm

Post by sigi »

Zett wrote:My "Surely Smallest Mouse" needs 21 instructions 8)
And yes, sometimes it generates a false answer, like closed source products :wink:
I don't consider that a valid solution.
Zett
Posts: 3
Joined: Mon Nov 03, 2008 8:31 pm

Post by Zett »

sigi wrote:
Zett wrote:My "Surely Smallest Mouse" needs 21 instructions 8)
And yes, sometimes it generates a false answer, like closed source products :wink:
I don't consider that a valid solution.
According to the rules of the game it is: The server accepted my solution.
snibril
Posts: 31
Joined: Sun Oct 26, 2008 11:18 pm

Post by snibril »

Thats called broken by Design :lol:
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Post by m!nus »

Zett wrote:And yes, sometimes it generates a false answer, like closed source products :wink:
And I though computers where there to not produce random results :/
tog
Posts: 70
Joined: Fri Nov 14, 2008 11:23 am
Location: Germany

Post by tog »

Oh, randomness is nothing bad, arbitrariness is evil :wink:
Post Reply