Broken Keys

Discussion of challenges you have already solved
klavierspieler21
Posts: 16
Joined: Fri Jul 13, 2007 12:21 am
Location: Waterloo

Broken Keys

Post by klavierspieler21 »

I "solved" this by using the fact that max(a,b) = (|a-b|+a+b)/2, and Newton's method to calculate the square root of (a-b)^2. However, it shouldn't have passed when a-b = 0 because I'm dividing by 0 in newton's method.

I got error messages but I still "passed"...

Here's my code:
0<1<1^1^-0^*11^1^/+2/1^1^/+2/1^1^/+2/1^1^/+2/1^1^/+2/1^1^/+2/1^1^/+2/1^1^/+2/1^1^/+2/1^1^/+2/1vd++2/p

The repeating 1^1^/+2/ is the recursive newton's method applied enough times.
ftfish
Posts: 12
Joined: Thu Aug 20, 2009 1:51 am

you had a good solution, but yet another

Post by ftfish »

I used the fact: when a<b, a/b equals 0.
max(a,b)=(a/b *a + b/a *b)/(a/b + b/a)

here's my code:

Code: Select all

0<0<1</*1<1<0</*+0<1</1<0</+/p
User avatar
livinskull
Posts: 22
Joined: Fri Jun 26, 2009 12:01 pm
Location: /dev/null
Contact:

Post by livinskull »

eat this:

Code: Select all

1<0</0^/<p
getting divide-by-zero warnings if second is larger, but who cares as long as it works :D
coderT
Posts: 17
Joined: Wed Nov 12, 2008 5:37 am

Post by coderT »

livinskull wrote:eat this:

Code: Select all

1<0</0^/<p
getting divide-by-zero warnings if second is larger, but who cares as long as it works :D
damn i thought that's not allowed.
Here is how I solved it:
1. except memory location 0, fill the whole memory with the content of memory location 1.
2. location = Mem[0] / Mem[1]
3. the greater number is: Mem[location]

this is stupid but worked.
jonik555
Posts: 43
Joined: Mon Aug 31, 2009 6:18 pm
Location: Prague

Post by jonik555 »

Oh no, I found other solution, but it is solution for next challenge :D Very nice one!!!!
OKOB
Posts: 2
Joined: Sat Mar 13, 2010 2:18 pm
Location: From Hell

Post by OKOB »

Another conventionally correct solution (All tests passed!)
111111111111111111111101<0</v<p!
Longer (1111111111111111111111101<0</v<p!) - not all tests passed
Shorter ( 11111111111111111111101<0</v<p!) - not all tests passed


Bad tests set or error in 'v' comand implementation (Longer don't work!)
arthur
Posts: 21
Joined: Fri Jul 23, 2010 12:44 pm

Re: you had a good solution, but yet another

Post by arthur »

ftfish wrote:I used the fact: when a<b, a/b equals 0.
max(a,b)=(a/b *a + b/a *b)/(a/b + b/a)

here's my code:

Code: Select all

0<0<1</*1<1<0</*+0<1</1<0</+/p
It seems not to work for negative integer. if a<0<b and |a|>|b|, a/b != 0.
my solution is

Code: Select all

0<1<-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-0^2/-1+4*g    1<p!0<p!
works for |a-b|<2^27
whattheh@ck
Posts: 16
Joined: Wed Jul 16, 2008 2:33 am
Location: here

Post by whattheh@ck »

I sort of cheated :wink:

Code: Select all

0<1</9*0^52*/3>3<25**-3<+g1<p!000000000000000000000000000000000<p!
all of those 0's seem to be a good enough buffer to pass all the tests...

I just fixed it to be more exact:

Code: Select all

1<0<1</9*0^52*/3>3<25**-3<+0^52*/3>3<25**-3<+3/gp!00<p!
it works due to an interesting fact that the sum of the digits in a multiple of 9 is 9.
hack the planet
User avatar
zjorzzzey
Posts: 11
Joined: Fri Oct 30, 2009 7:31 pm
Location: NL

Post by zjorzzzey »

Code: Select all

0<1<1^1^10>01>/<vdp
Works because memory is initialized with zeroes by default.

Seen more beautifull solutions though...
kalunos
Posts: 7
Joined: Sat Jun 18, 2011 7:22 pm
Location: germany

Post by kalunos »

here comes my (straightforward 8) ) receipt (>0 numbers only, but passed the test) ...

0<1</2+0^1-/1-<p

which means: load the 2 nums, divide .. result is 0 (if S0<S1) or any n >0.

then calc ( (n+2) / (n+1) ) which gives "2" for n=0 only, "1" else.

looking forward for more broken keys :wink: ....

happy coding!
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

0<1<-088*8*8*8*8*8*8*8*8*-2*/1+4*g0<p!1<p!

Dividing the difference of the two numbers by -(2^31) gives either -1 or 0, from there it's easy.

Now to do it without the division instruction... I really have no clue how to :(
compudemon
Posts: 33
Joined: Sat Aug 13, 2011 2:13 pm

Post by compudemon »

i cheated with divide
if smallnumber > 0 and < bignumber then ( smallnumber + bignumber - 1) / bignumber = 1
else = 0

0<1</88888****1-+8/8/8/8/8/4*g1<p!0<p

yeah this wont work if the test has a big number in it but who cares
Chnty
Posts: 6
Joined: Thu Sep 08, 2011 3:53 am

Post by Chnty »

Code: Select all

 1<0</0^2*1v1+/<p 
Math rules!
Because 2x/(x+1) is 0 for 0 and 1 for anything else
sascha27
Posts: 5
Joined: Wed Jan 02, 2013 10:03 am

Post by sascha27 »

I kind of used a shift operation, 32 times so it was big enough for integer values

0<1<-2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/01-*<p

:P
rhian
Posts: 2
Joined: Mon Mar 16, 2009 2:25 pm

Post by rhian »

Code: Select all

1<0<1</>0<p
i just save the value of M1 into the result of M0/M1. if M0 < M1 then the result is 0 and higher M1 value is stored into M0 which I print in any case.
Post Reply