@@ -0,0 +1,2245 @@
+class P58_SpiralPrimes %7B%0A    // Project Euler - Problem 58 - Spiral primes%0A    // Starting with 1 and spiralling anticlockwise in the following way,%0A    // a square spiral with side length 7 is formed.%0A    //        37 36 35 34 33 32 31%0A    //        38 17 16 15 14 13 30%0A    //        39 18  5  4  3 12 29%0A    //        40 19  6  1  2 11 28%0A    //        41 20  7  8  9 10 27%0A    //        42 21 22 23 24 25 26%0A    //        43 44 45 46 47 48 49%0A    // It is interesting to note that the odd squares lie along the bottom right diagonal,%0A    // but what is more interesting is that 8 out of the 13 numbers lying along both diagonals are prime;%0A    // that is, a ratio of 8/13 %E2%89%88 62%25.%0A    // If one complete new layer is wrapped around the spiral above,%0A    // a square spiral with side length 9 will be formed.%0A    // If this process is continued, what is the side length of the square spiral%0A    // for which the ratio of primes along both diagonals first falls below 10%25?%0A%0A    private static final int LIMIT = 10;%0A%0A    public static void main(String%5B%5D args) %7B%0A        String message = %22The side length for which the prime ratio first falls below 10%25%25 is %25,d.%5Cn%22;%0A        int length = P58_SpiralPrimes.getLength(LIMIT);%0A        System.out.printf(message, length);%0A    %7D%0A%0A    private static final int MAX_SIZE = 100;%0A    private static int%5B%5D%5B%5D spiral = new int%5BMAX_SIZE%5D%5BMAX_SIZE%5D;%0A    private static int spiralSize = 0;%0A    private static int sprialMaxValue = 0;%0A%0A    private static int getLength(int limit) %7B%0A        for (int length = 3; length %3C= MAX_SIZE; length += 2) %7B%0A            growSpiral(length);%0A            if (getSpiralRatio() %3C 10) return length;%0A        %7D%0A        return -1;%0A    %7D%0A%0A    private static float getSpiralRatio() %7B%0A        return 0;%0A    %7D%0A%0A    private static void growSpiral(int length) %7B%0A        while (!spiralComplete(length)) %7B%0A            int i = getNextI();%0A            int j = getNextJ();%0A            setSpiralValue(i, j);%0A        %7D%0A        spiralSize = length;%0A    %7D%0A%0A    private static void setSpiralValue(int i, int j) %7B%0A        sprialMaxValue++;%0A        spiral%5Bi%5D%5Bj%5D = sprialMaxValue;%0A    %7D%0A%0A    private static boolean spiralComplete(int length) %7B%0A        return sprialMaxValue %3E= Math.pow(length, 2);%0A    %7D%0A%7D%0A

add solution outline