Ok guys,
Here is a challange for you :D.
The GOAL is to make a single separate .java file that calls CubicRootChallenge.checkCubicRoot() and is able to get true.
You are not able to use reflection.
import java.math.BigInteger;
import java.security.SecureRandom;
/**
* RULES:
*
* <p>1. Write a class that by calling CubicRootChallenge.checkCubicRoot(), is able to reach the *GOAL* line
*
* <p>2. Solve the problem in a single separate .java file which compiles and runs with JDK 6/7/8
*
* <p>3. Your code must run with the security manager enabled (java -Djava.security.manager your.Class)
*
*
*/
public class CubicRootChallenge {
// Number of BITS for the number
public static final int BITS = 10000;
// Generate random number with said bits [0 <--> 2^BITS - 1], and elevates it ^3
private static final BigInteger NUMBER = new BigInteger(BITS, new SecureRandom()).pow(3);
// Methods that prints out when passed BigInteger is cubic root of NUMBER
public static void checkCubicRoot(BigInteger numberToTest) {
// Check if numberToTest is cubic root of NUMBER
if (NUMBER.divide(numberToTest).divide(numberToTest).equals(numberToTest)) {
// THE GOAL IS TO REACH THIS LINE!
System.out.println("YOU WIN!");
}
}
}