Patience

KindeX
Posts: 2
Joined: Thu Jul 22, 2010 6:42 pm

Post by KindeX »

KindeX wrote:So the question is if the checker accepts only one predefined correct answer, or checks every every answer with some algorithm.
I've just solved this challenge. The answer is YES - the only one first generated number is correct answer. So, use proper random generator.
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

I'm wondering - does this depend on a certain version of Java? I am using build 1.6.0_26-b03 and when I try to compile again the decompiled Patience.class, I get two errors:

Code: Select all

Patience.java:9: incompatible types
found   : java.util.Random
required: java.lang.String[]
    paramArrayOfString = new Random(739391L);
                         ^
Patience.java:14: cannot find symbol
symbol  : method nextLong()
location: class java.lang.String[]
      while ((l = paramArrayOfString.nextLong()) < 0L);
                                    ^
Should I use a different decompiler (this was done with jd-gui-0.3.3.windows), or a different version of the Java SDK?
Karian
Posts: 75
Joined: Wed Jan 09, 2008 10:21 am

Post by Karian »

No idea what causes the problem exactly, since I don't know which steps you took exactly, but it looks like a bit of java Knowledge can solve your problem.
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

I thought that when you decompile a given Java .class file, and then re-compile it again, you would get a class file which can be executed. Not so here, where the re-compilation fails with said errors.

Now, it's easy to fix it to something like

Code: Select all

Random rand_sequence = new Random(739391L);
and then it would run - slowly ;) Still I don't really get why the decompilation leads to erroneous source code.

Now, after fixing that I tried to replace the "BigInteger" with "long", but that gave me an error because of the string index array in the do...while loop taking on negative values after a certain amount of iterations. Well, I'll have to find a different approach it seems.
tripleedged
Posts: 10
Joined: Fri Apr 16, 2010 11:24 pm

Post by tripleedged »

This one was quite funny...
I thought I had tweaked it enough to run it in an acceptable amount of time. After some minutes of running I got curious if I missed some detail and wanted to get some of the original numbers to check my calculation. After I restored the initial (just little improved) code I wanted to stop the program and it just showed the solution...
Phew, if I had given up few seconds early, I still would not have solved it...
moose
Posts: 67
Joined: Fri Jul 16, 2010 7:32 pm

Post by moose »

Is it enough to solve the 20,000-for-loop to a multiplication and an addition? Or is more tweaking required? It just runs. I think I let it try for 30 min (so until 18:25).
wischi
Posts: 9
Joined: Sun Apr 08, 2012 6:41 am

Post by wischi »

need some help :-)

after some math-hacks i figured out the rnd-number which passes the while-condition, but submit the answer ends in 'incorrect' :-( FUUUU

am i wrong? thx in advance
User avatar
laz0r
Posts: 290
Joined: Thu Feb 04, 2010 4:18 pm
Location: Within the depths of Unix

Post by laz0r »

wischi wrote:need some help :-)

after some math-hacks i figured out the rnd-number which passes the while-condition, but submit the answer ends in 'incorrect' :-( FUUUU

am i wrong? thx in advance
I admit my evidence is limited, but I suspect your answer is wrong :) sorry!
There is no spoon.
magnus
Posts: 20
Joined: Thu Mar 05, 2009 2:29 pm

Post by magnus »

Takes ~7 Seconds with the right optimizations ;-)
eduarrrd
Posts: 3
Joined: Mon Aug 06, 2012 8:37 pm

Post by eduarrrd »

Is the challenge really working?

I decompiled the code, optimized it and let it run (<10min to finish). However, the challenge is not accepting my result. To make sure I got it right, I kept both the original and my version of the relevant part and looked at the difference between the two results for half an hour (always 0). Could it be a java version issue (running 1.7.0_06 (IcedTea7 2.3.4))? The number I'm getting is 9245[10 digits]7183.
rabuf
Posts: 2
Joined: Sat Jul 09, 2011 2:24 am

Post by rabuf »

Same issue as eduarrd. Making some optimizations to the math involved and running it I got an answer after a few minutes that was not accepted. I'm guessing the seed to the RNG is important and I kept it, but unfortunately it seems that my version is generating a different sequence.

Java version, on OS X:

java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06-451-11M4406)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01-451, mixed mode)

Any suggestions besides my next step (run it printing out value that satisfies the test and try them all)?
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

Well several people solved it after eduarrd's post, so it should be doable still.
rabuf
Posts: 2
Joined: Sat Jul 09, 2011 2:24 am

Post by rabuf »

Well, disregard my previous comment. I did something to screw up the code in my attempt to make it run quicker. Tested the RNG across several java versions and it produced the same results as my original run.
Post Reply