Live data from Hacker News

Java Puzzle: Square Root

corner.squareup.com

31–40 of 61 posts

Re: Java Puzzle: Square Root

#31

I hate to break it to you but "n" is not final. Hence, you can reassign any BigInteger to it. Why not just set n = 9 and the root = 3... Immutability is your friend. Use it or lose it.

But n is also private, so you can't reassign it without using setAccessible or changing the security manager, both forbidden by the rules.

Re: Java Puzzle: Square Root

#32

I hate to break it to you but "n" is not final. Hence, you can reassign any BigInteger to it. Why not just set n = 9 and the root = 3... Immutability is your friend. Use it or lose it.

You can't assign anything to a private variable.

Re: Java Puzzle: Square Root

#33

I hate to break it to you but "n" is not final. Hence, you can reassign any BigInteger to it. Why not just set n = 9 and the root = 3... Immutability is your friend. Use it or lose it.

But "n" is private and the rules state the solution must be in a different class. Thus you can't simply reassign it.

Re: Java Puzzle: Square Root

#34
post #5

I'm not sure this is interesting. Unless I'm missing something, the question is "find what way of breaking the compartmentalization of the JVM we haven't forbidden in these English-language rules".

Yes, I believe you and cromwellian have hit upon the main point. Or, to be more succinct, "do you know about Java spi."

Re: Java Puzzle: Square Root

#38
post #27

I'm surprised nobody's given the obvious algorithm yet: while(i Before anyone complains, this algorithm is correct and does not break any of the rules as far as I can tell. :) I think the timing attack is probably what he's really looking for. Edit: as mattvanhorn pointed out, answer() is void, but that's ok... changed to a "constant time" algorithm. :)

answer() has a void return, although I suppose you might be able to watch System.out to see if it worked.
Post reply on HN