Page 1 of 2
Brokenest Keys
Posted: Wed Dec 24, 2008 1:24 am
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!
Posted: Wed Dec 24, 2008 1:36 am
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.
Posted: Wed Dec 24, 2008 1:50 am
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.
Oh, c'mon - it's not brokenEST
Posted: Wed Dec 24, 2008 3:00 am
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.
Does it deserve a bridge over the river ?
[Edit]
Let's break also d,v, and spacebar - they are useless here anyway.
[/edit]
Posted: Wed Dec 24, 2008 3:56 pm
by MerickOWA
I think adum needs to just buy a new keyboard!
Posted: Wed Dec 24, 2008 5:46 pm
by tails
Posted: Wed Dec 24, 2008 8:57 pm
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
Posted: Thu Jan 08, 2009 4:40 pm
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.
Posted: Thu Jan 08, 2009 5:16 pm
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
Posted: Thu Jan 08, 2009 7:00 pm
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.
Posted: Thu Jan 08, 2009 7:07 pm
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.
Posted: Thu Jan 08, 2009 9:05 pm
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.
Posted: Sat Jan 10, 2009 9:31 pm
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!
Posted: Wed Jan 14, 2009 10:55 am
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.
Posted: Tue Feb 10, 2009 6:15 pm
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
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