King Rat

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

King Rat

Post by lukas »

my code:

0<10>0^0<<0^82*?:1-3?0<<0<1+0>5cdp
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Post by m!nus »

you have to make it much shorter: there's one with 21 instruction limit
brazzy
Posts: 14
Joined: Fri Nov 07, 2008 2:30 am
Location: Munich, Germany
Contact:

Post by brazzy »

Bah. I'm a Java programmer, I don't do terse. So here's one that neither (ab)uses the call stack nor writes to memory:

0<991++1^1^<0^2v:1+4?1v2vd1-0^8?084*1+-gdp
brazzy
Posts: 14
Joined: Fri Nov 07, 2008 2:30 am
Location: Munich, Germany
Contact:

Post by brazzy »

BTW, lukas, you code has a bug: it terminates when it encounters a 0, so if that's part of the actual data, and the largest number comes afterwards, the result is wrong. But apparently that case does not occur in the tests that determine whether you pass.

And after sitting over this for 3 hours, I can't see for the life of me how to get it down below 29 instructions, let alone 21, seeing how even the simplest operations take 5 or more instructions.

I only managed to get down to 28 by using 0 to terminate and assuming only positive numbers; unfortunately that's not a valid assmption.
the_impaler
Posts: 61
Joined: Wed Apr 30, 2008 3:31 am

Post by the_impaler »

brazzy wrote:BTW, lukas, you code has a bug: it terminates when it encounters a 0, so if that's part of the actual data, and the largest number comes afterwards, the result is wrong. But apparently that case does not occur in the tests that determine whether you pass.

And after sitting over this for 3 hours, I can't see for the life of me how to get it down below 29 instructions, let alone 21, seeing how even the simplest operations take 5 or more instructions.

I only managed to get down to 28 by using 0 to terminate and assuming only positive numbers; unfortunately that's not a valid assmption.
I would say that 3 hours is not that long. It took me a while , may be 3 weeks may be more to find the correct solution for 27. Then I put away HVM challenges and switch to others. Then I came back and got those mice down to 22. The mice problems are good in sense that it's pure coding and no IDE or assembler would help you.
tog
Posts: 70
Joined: Fri Nov 14, 2008 11:23 am
Location: Germany

Post by tog »

Well, it didn't take me too long to discover the 21-solution. So I don't think that many hours or even days are necessary. Of course, if you're stuck, it may be reasonably to stand back and come again later. I also found quinine much harder (and actually needed some days to solve it), because there are many more possibilities to try out.

@brazzy: It's nice and important if you know how to write valid programs. But this is the wrong place for the "correct" way of programming... this is hacker.org: everything that passes the test is a correct solution. :wink:
User avatar
livinskull
Posts: 22
Joined: Fri Jun 26, 2009 12:01 pm
Location: /dev/null
Contact:

Post by livinskull »

My Code:

Code: Select all

preserve 100

	var pointer
	var tmp

mov tmp, [pointer]
start:
	push tmp
	push [pointer]
	jg next		
	mov tmp, [pointer]
next:
	inc pointer
	push 20
	push pointer
	jg start
	pi tmp
Assembled to:

Code: Select all

55*4*<<99*92*+2+>99*92*+2+<55*4*<<:1-98+?55*4*<<99*92*+2+>55*4*<1+55*4*>54*55*4*<:1-792+*01-*?99*92*+2+<p
Yes, its kinda big, but im lucky my assembler finally works so far :P
quangntenemy
Posts: 8
Joined: Thu Jul 02, 2009 3:41 pm

Post by quangntenemy »

My code:

Code: Select all

0<45*>10^<0^45*<:1:3?d4g45*>1+0^45*:01-:158*-?45*<p
Force4
Posts: 29
Joined: Wed Dec 16, 2009 8:33 pm

Post by Force4 »

Well I'm quite ashamed of mine.

Code: Select all

0<00^991++:75*1-?1+0^2v2v<1^1^:1-01-*7?1vd1v3cd1v3cdp
Too long, call stack flooder, etc.
The "21 instructions" challenge is gonna take me some time...
chephy
Posts: 17
Joined: Sat Oct 16, 2010 4:39 pm

Post by chephy »

Another straightforward version:

Code: Select all

0<999++>12g1+0^54*6g54*1+g:62**g       999++<p!0^<999++<:77*4+*g                                                     0^<999++>055*5*  -g
NOP slides! xD
MrBlueSky
Posts: 3
Joined: Tue Jun 30, 2009 9:48 pm

Post by MrBlueSky »

My code:

Code: Select all

[9*9]=0;
[9*8]=[[9*9]];
while (4*5>[9*9]) {
        if ([[9*9]] > [9*8]) {
                [9*8] = [[9*9]];
        }
        [9*9] = [9*9]+1;
}
printi [9*8];
compiled to:

Code: Select all

99*00^2v>d98*00^2v>d45*99*<:1:92+      ?01        g10:991+*5+  ?99*<<98*<:1:92+      ?01        g10:92*6+    ?98*99*<<0^2v>d0        g99*99*<1+0^2v>d0996+*4+-g98*<p!
Let's hope there is only one with an instruction limit.... :oops:
kalunos
Posts: 7
Joined: Sat Jun 18, 2011 7:22 pm
Location: germany

Post by kalunos »

look, here comes my quick'n-dirty solution for this one...

it uses a !subroutine! for comparing the s0/s1 values in place ..

44*g!1^1^:1:2?1vd$! 0<1<5c 2<5c 3<5c 4<5c 5<5c 6<5c 7<5c 8<5c 9<5c 91+<5c 92+<5c 93+<5c 94+<5c 95+<5c 96+<5c 97+<5c 98+<5c 99+<5c 99+1+<5c p

lots of bits wasted, but why not, i got enough of them here :lol: ... its all for speed and read-ability of course 8) !! ...

happy coding / greets - max.
compudemon
Posts: 33
Joined: Sat Aug 13, 2011 2:13 pm

Post by compudemon »

10<29*1+2^:1+74*?1^<1^:1+4?d0^<1v1+1v094*6+-gp

i wrote it out in pseudo-code and compiled by hand
horst
Posts: 24
Joined: Fri Mar 06, 2009 11:07 am
Location: Germany

Post by horst »

01+0^<0<:1:01-:5?0^<0>0^45*1-:3?1c0<p

I thought 37 instructions weren't that bad until I saw that mouse challenge :shock:
rmplpmpl
Posts: 113
Joined: Sun Oct 26, 2008 10:38 am
Location: Germany

Post by rmplpmpl »

gosh, did this, but I won't tell you my #s of instructions... for King Mouse I will have to strip it down significantly...
Post Reply