Brokenest Keys
Brokenest Keys
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!
I wouldn't have thought to use memory like that for this challenge. If adum makes another where '+' is broken too i give up!
-
- Posts: 61
- Joined: Wed Apr 30, 2008 3:31 am
I deleted my code as well.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 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.
-
- Posts: 61
- Joined: Wed Apr 30, 2008 3:31 am
Oh, c'mon - it's not brokenEST
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]
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]
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
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
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.
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.
- Yharaskrik
- Posts: 31
- Joined: Wed Nov 05, 2008 11:44 am
- Location: Germany
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.
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
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!
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.
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:
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
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
Very nice challenges