Brokenest Keys

Discussion of challenges you have already solved
gfoot
Posts: 269
Joined: Wed Sep 05, 2007 11:34 pm
Location: Brighton, UK

Post by gfoot »

I only just got round to solving Brokener and Brokenest, but I'm happy that my solutions are reasonably short. :)

Code: Select all

0<1<-3*0^1+/<p
0<1<81^2+>92^2+>11+0^<8-gddp
95+c4gddp!98+g0<1<21^2+>32^2+>11+0^<4+c
One problem I have is that I find it distasteful to rely on input ranges or other properties which aren't specified in the challenge description. :/ The "broken key[s]" solution above works for any inputs whose difference can be tripled, including negative numbers, but the other two only work for non-negative numbers within memory range, and its cycle count is proportional to the smallest's size, which is the greater limitation. Brokener here works for the smaller number being up to 1246, Brokenest up to 711. I get the feeling the lots-of-spaces-in-code versions can probably manage higher numbers, maybe up to the order of the maximum cycle count (10000), and their limitation is the difference between the numbers rather than their overall size. But I think I prefer small code size at the moment. :)

Of course I doubt that it's possible to solve these in a way that doesn't limit the inputs to a rather small range, based on memory indexing and cycle counts. I'd just prefer it if the limits were stated in the challenge.
megabreit
Posts: 141
Joined: Sat Jan 03, 2009 3:33 pm

Post by megabreit »

I demand the ugliest (really?) and biggest... but probably fastest solution :shock:
It's 131613 instructions long and takes 24 cycles to complete regardless of the number difference.

My program assumes, that values are in the range of 0<=x<=255, which makes it even uglier.
I use a static lookup table of call instructions; either 4c (for mem 0) or 8c (for mem 1)
Then I calculate mem0*256*2+mem1*2 and simply jump to this offset into the lookup table.
The call instruction points back to the start and prints the bigger number.
I did not use spaces for repeating patterns, because this would terribly slow things down.

Code: Select all

 
24*g0<p!1<p!0<888***1<2*+g4c(254 times 8c)(2 times 4c)(253 times 8c) ... (255 times 8c)
My biggest problem was to submit this gozilla of a program because it always stopped with a network timeout.
Changing the web page to use POST for submit finally worked.

My other solutions were:

Code: Select all

 
0<1<1^1^/1?dp
0<1<1^1^/3*gp!!dp!dp!dp!dp!dp!dp!dp!dp!dp!dp!dp!
0<1<1^1^-884**+3*gp!!..(several p!!)..p!!dp!..(several dp!)..dp!
The last 2 use the same idea of a lookup table as described above, but the size of the table is smaller because of the achievable size reduction using / and -.

I second your opinion regarding the "Broken* Key*" challenges: @Adum: Enough with this, this is no fun anymore :lol:
jonik555
Posts: 43
Joined: Mon Aug 31, 2009 6:18 pm
Location: Prague

Post by jonik555 »

I it is almost same is I used from broken keys, always working very well :D

Code: Select all

0<3>1<2>20<>31<>54> 4<<8*g4<1+4>45*c                                                                                          4<<<p!
arthur
Posts: 21
Joined: Fri Jul 23, 2010 12:44 pm

Post by arthur »

nice challenges
my solution:

Code: Select all

0<1<80<56+1<00>01>>>00^<g1+145*+cdp!d1vp!
similar to my previous one, it works for positive integers and requires the small number smaller than the maximum cycles

i just find out all test cases are positive integers, but the challenge doesn't say that. i have no idea if there are negative integers
muharred
Posts: 1
Joined: Mon Jul 19, 2010 10:47 am

Post by muharred »

Wow. Some really nice ideas here. I haven't thought about using the memory at all. :-D Instead my solution relayed on a large count of "$". I looped incrementing both variables by 1 and in every loop cycle I loaded the original value of the current variable and tried to jump to <some constant>+<current variable value> for both variables. Both numbers were positive, both were less than 255 (or something like that). So I just filled all the space behind the main program with "$" and placed p! in the end. Whoever got there first was printed. :-) Without optimization my solution barely made it - it ran out of cycles for small numbers when they reached 300 and the <maximum accepted value> + <program size> has to be less than this mark.
I wonder if I would end up using the memory if the range was bigger.
User avatar
MyNameIsAlreadyTaken
Posts: 31
Joined: Sun Oct 17, 2010 10:21 am
Location: Germany

Post by MyNameIsAlreadyTaken »

Actually, this one was pretty easy after i saw jonik's solution in the last Thread. I don't know if it shouldn't be removed aswell.


I would probably never have had the idea to use the memory, but i somehow managed it to make a code based on his algorithm:

Code: Select all

000<61<00>01>>0^<6+1v>  0^<g1+64*c    3g p! 1^g1v95++1v1+64*cp!
uws8505
Posts: 32
Joined: Sun Jan 23, 2011 8:57 pm

Post by uws8505 »

Wow, everyone here is such a genius :shock:

My idea(and code) was very similar to megabreit's, though my code is a little shorter(131096 instructions) and takes a little longer(25 cycles)...
I had to (really) make a C++ program to output the whole HVM code.
And the code didn't fit into the submission form, so I used Python :D to submit the whole thing.
User avatar
zjorzzzey
Posts: 11
Joined: Fri Oct 30, 2009 7:31 pm
Location: NL

Post by zjorzzzey »

Hmm... I just adopted my solution for 'brokener keys' a bit to avoid the '-'.
This resulted in not too optimized, but working code:

Code: Select all

0<1<1^1^00>01>177*7*>1^1^<54**g<27**g1+1v1+1v37*c! dddp
It assumed the numbers were below 343, which they apperently did.

With such a broken keyboard, i would seriously consider buying a new one though :D
tompko
Posts: 11
Joined: Fri Feb 25, 2011 10:32 am
Location: London, UK

Post by tompko »

My solution:

Code: Select all

0<1<01>00>12^>00^<91+*g11^>1+96+cd0^<vp
It fills the memory from location 0 to number 0 with 1s and then reads the memory location of number 1. Like others it'll only work if the numbers are less than the number of memory locations and probably due to the cycle limit and my sloppy coding for numbers much smaller than that :)
compudemon
Posts: 33
Joined: Sat Aug 13, 2011 2:13 pm

Post by compudemon »

yeah i could make it more efficient but it works

8g0^<g1+2c5g1+<p!0<1<00>01>61^2*>0^2*1+2^1v>62^2*>1v2*1+>02c
avrrobot
Posts: 51
Joined: Fri Mar 04, 2011 2:54 pm
Location: Germany

Post by avrrobot »

Here is my code:

Code: Select all

10<2+>211^>1+0^<2*g7c1<2+<4*g1<p!0<p
I think its very similar to the other solutions. It will will set the memory on the position of the first number to 1, then fill everything with ones up to there and then check the memory position of the second number.
User avatar
CodeX
Posts: 350
Joined: Fri Oct 17, 2008 5:28 pm

Post by CodeX »

I looks like I can take the accolades for longest + ugliest code from megabreit and slowest from elsewhere! The code is 1806 bytes long, takes 1802+6(n-1) cycles and limited to 0<n<=250 where n is the lowest of the two values. It basically uses memory[0:250] as a lookup table for function addresses where there are 3 functions: one to print the first entry, one to print the second entry and a third to loop through by abusing calls - roughly equivalent Python for the code is

Code: Select all

A = getMemory(0)
B = getMemory(1)
def printA():
    global A
    print(A)
    exit()

def printB():
    global B
    print(B)
    exit()

def loop():
    global i
    i += 1
    lookup[i]()

lookup = [loop]*250
lookup[A] = printB
lookup[B] = printA
i = 0
loop()
And the actual code is given by

Code: Select all

code = '8g2vp!1vp!0<1<89*55**  0'
code += '1^1^>1+' * 249 
code += '1^1^>dd62^>21^>0                 1+0^<c'
Hooray!
Post Reply