Level 1
----------------------------------------
Embedded in this block of text is the password for level 2.
The password is the longest substring that is the same in reverse.
As an example, if the input was "I like racecars that go fast"
the password would be "racecar".
Enter the password to access level 2:
Level 2
----------------------------------------
Congratulations. You have reached level 2.
To get the password for level 3, write code to find the first prime
fibonacci number larger than a given minimum. For example, the first
prime fibonacci number larger than 10 is 13.
When you are ready, go here or call this automated
number (415) 799-9454.
You will receive additional instructions at that time. For the second portion
of this task, note that for the number 12 we consider the sum of the prime divisors
to be 2 + 3 = 5. We do not include 2 twice even though it divides 12 twice.
Enter the password to access level 3:
go here
Step 1. Use your code to compute the smallest prime fibonacci number
greater than 227,000. Call this number X.
Step 2. The password for level 3 is the sum of prime divisors of X + 1.
Note: If you call the number instead, it will check your answer for step 1.
public class FibonacciPrimes {
private static final int N = 1000000;
private boolean[] prime = new boolean[N + 1];
private void getPrimes() {
for (int i = 2; i < N; ++i) {
prime[i] = true;
}
for (int i = 2; i <= Math.sqrt(N); ++i) {
if (prime[i]) {
for (int j = i + i; j < N; j += i) {
prime[j] = false;
}
}
}
}
private int p = 1;
private int getNextPrime() {
++p;
while (!prime[p]) {
++p;
}
return p;
}
private int getFibonacci(int t) {
getPrimes();
int a = 1;
int b = 1;
while (true) {
int c = a + b;
if (c > t && prime[c]) {
return c;
}
a = b;
b = c;
}
}
private int getPrimeDivesSum(int x) {
int sum = 0;
p = 1;
while (x != 1) {
int f = getNextPrime();
if (x % f == 0) {
sum += f;
while (x % f == 0) {
x /= f;
}
}
}
return sum;
}
public static void main(String[] args) {
FibonacciPrimes fp = new FibonacciPrimes();
int x = fp.getFibonacci(227000);
System.out.println(x);
System.out.println(fp.getPrimeDivesSum(x + 1));
}
}
Level 3
----------------------------------------
Congratulations. You have reached the final level.
For the final task, you must find all subsets of an array
where the largest number is the sum of the remaining numbers.
For example, for an input of:
(1, 2, 3, 4, 6)
the subsets would be
1 + 2 = 3
1 + 3 = 4
2 + 4 = 6
1 + 2 + 3 = 6
Here is the list of numbers you should run your code on.
The password is the number of subsets. In the above case the
answer would be 4.
Enter the password to complete the challenge: