Brokenest Keys

Discussion of challenges you have already solved
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Brokenest Keys

Post by MerickOWA »

Have to say that after seeing how efe did it I managed to solve this one pretty easily.

I wouldn't have thought to use memory like that for this challenge. If adum makes another where '+' is broken too i give up!
tails
Posts: 191
Joined: Tue Jun 10, 2008 7:51 pm
Location: Tokyo

Post by tails »

In fact, this challenge was born from efe's code. I had to ask adum to delete the code on the forum when I told him the idea without "-", but it seems I was a bit too late.
the_impaler
Posts: 61
Joined: Wed Apr 30, 2008 3:31 am

Post by the_impaler »

tails wrote:In fact, this challenge was born from efe's code. I had to ask adum to delete the code on the forum when I told him the idea without "-", but it seems I was a bit too late.
I deleted my code as well.
I just modified mine solution - it's rather easy to do , just shift everything by 2 up and I already had the loop going in + direction anyway.
the_impaler
Posts: 61
Joined: Wed Apr 30, 2008 3:31 am

Oh, c'mon - it's not brokenEST

Post by the_impaler »

Let's just skip those little by little steps and call "Just trash it" challenge -
broken keys include :,?,!,/,*,- and numbers 2-9.
It's doable although painful. :twisted:
Does it deserve a bridge over the river ?
[Edit]
Let's break also d,v, and spacebar - they are useless here anyway.
[/edit]
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Post by MerickOWA »

I think adum needs to just buy a new keyboard! ;)
tails
Posts: 191
Joined: Tue Jun 10, 2008 7:51 pm
Location: Tokyo

Post by tails »

Yeah, then he should have a happy hacking :D


http://www.pfusystems.com/hhkeyboard/hhkeyboard.html
User avatar
m!nus
Posts: 202
Joined: Sat Jul 28, 2007 6:49 pm
Location: Germany

Post by m!nus »

too bad i read efe's code, i bet i would have come up with a similar solution aswell.
anyway, managed to get it in 30 instructions, could make it without * aswell :)
bruderm
Posts: 2
Joined: Thu Dec 18, 2008 12:58 am

Post by bruderm »

My solution contains a lot of spaces and dosen't work for certian values (the bigger value has to be bigger than 5). I would like to see eve's code (haven't seen it at the broken key threat) so I can see if there's a better way to do.
MerickOWA
Posts: 182
Joined: Mon Apr 07, 2008 5:54 pm
Location: HkRkoz al KuwaiT 2019 HaCkEr 101

Post by MerickOWA »

Since I think this is the last in the chain, I think its safe to post.

My code basically involved reading the 2 values out of memory (and then initializing those locations to 0).

I would use the values as a memory address to write a '1' in.

I then looped sequentially memory until I found the first non-zero location. Then continued on until I encountered a second non-zero location.

That was the basic idea anyway.

I solved the problem of my code looping forever when the two values were the same by adding a '1' to the memory locations rather than just setting it to one. That way it became a '2' if both values were the same.

Then as i read from memory i would multiply the value read from memory by a constant value and used it for a 'g' instruction. A '0' meant i didn't jump at all, a '1' meant i jumped to the next loop... and a '2' meant that i jumped to the end of my program. Just had to come up with the right constant and space my program out a bit...

Could probably be more efficient, but it worked ;)
bruderm
Posts: 2
Joined: Thu Dec 18, 2008 12:58 am

Post by bruderm »

My idea is not that much different but somehow it came in my mind that I have to store the actual values and not a 1 into that memory cells. I then jumped the value in that cell with g. Very stupid actually. Thats why I have that many space in my code.
For the two equal value problem i just stored one of the two values at memory cell 729 (999**) so if the two values are equal the cell 729 is the second cell unequal 0.

Edit: I just overthought things a bit and for my idea for solving the two equal values problem it is necessary to put the values into the memory cells because its what I'll print.

But your idea is more beautiful anyhow.
User avatar
Yharaskrik
Posts: 31
Joined: Wed Nov 05, 2008 11:44 am
Location: Germany

Post by Yharaskrik »

Hi!
I also use the values as a memory address but write offsets for the
'g' command. The "short" jump pushes 1 and the "long" jump pushes
0 to the stack. Whatever jump will happen as the last jump will define
the larger number. So there is no problem with two equal values.
User avatar
efe
Posts: 45
Joined: Sun Oct 26, 2008 10:28 am
Location: germany

Post by efe »

Hi there,

I'd like to give you my very nice and short solution to 'Brokener Keys' again. It inspired tails to suggest this follow-up challenge.

Code: Select all

80<>81<>888**1-0^<8-gp
wrtlprnft
Posts: 28
Joined: Sun Nov 09, 2008 4:48 pm

Post by wrtlprnft »

Not having been spoiled before I probably submitted the ugliest ever answer with 5517 instructions (no spaces) and a limit to numbers ≤ 250…

It works as follows: fill the stack with 250 zeroes and 250 ones, then read the first value and backup it to a new memory slot n. Now, 250 times, copy the nth stack value and increment n by 2. Then use the generated stack mess as a lookup table and look up the corresponding element for the second value. Multiply this by the second value and save the result in another spot. Rinse and repeat with the two numbers swapped, but 249 zeroes and 251 ones. Add the two results and you're done.

Obviously I'm somewhat embarrassed now that I see your solutions…

My solution has one advantage, though: If there ever is a challenge without 'g' I'll beat it :-)

Oh, and screw those darn integer overflow exceptions. I so much wanted to generate a -1!
Last edited by wrtlprnft on Mon Mar 23, 2009 7:56 am, edited 1 time in total.
papa
Posts: 13
Joined: Wed Oct 29, 2008 7:51 am
Location: Germany

Post by papa »

I pushed x zeros and y ones on the stack, then took the x-th value from the stack and returned the corresponding number x or y. This worked without arithmetic operations or extensive memory but only for numbers between 0 and a certain limit and the program size was about four times that limit.
theStack
Posts: 72
Joined: Sun Nov 02, 2008 12:46 am

Post by theStack »

It's very interesting to read the various approaches for solving this challenge.
Especially efe's solution for "Brokener Keys" is just ingenius - that's what I call real programming art 8)

However, my solution for the (I guess?) last challenge in the chain is as follows:

Code: Select all

0<1<>1<0<> 1 1+0^<0^3*gd94+c [... LOTS of spaces...] p
In the relative jump with g I can't go backwards due to the - restriction, so I just replaced it with a call "c". I feared that there would be a call stack overflow after some time, but happily it all worked.

Very nice challenges :)
Post Reply