/*
 * The MIT License
 *
 * Copyright 2015 Sanket K.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package eratosthenes;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

/**
 *
 * @author Sanket K
 */
public class Eratosthenes {
    
    /*
    * Pick candidate
    * Start eliminating multiple of candidates until we are at n
    * pick next available candidate
    * rinse and repeat
    */
    public void sieve1(int n) {
        
        int [] data = new int[n+1];
        
        // Create the initial dataset
        // skip over 0 and 1
        for (int i = 2; i <= n; i++) {
            data[i] = i;
        }
        System.out.println("Our initial list = " + Arrays.toString(data));
        
        int index = 2;
        int candidate;
               
        while(index <= n) {
            candidate = data[index];
            if (0 == candidate) {
                index++;
                continue;
            }
            
            System.out.println("cand = " + candidate);
            // picked candidate
            int candidate_index = index + candidate;
            //System.out.println("candidate_index = "+ candidate_index);
            //mult = cand;
            //System.out.println("Mult = " + mult);
            
            while ((candidate_index <= n) && (data[candidate_index] <= n) && (0 != data[candidate_index])) {
               data[candidate_index] = 0;
               candidate_index += candidate;
               System.out.println(">>index2 = " + candidate_index);
            }
            index++;                        
        }
        System.out.println("Final = " + Arrays.toString(data));                
    }
    
    public void sieve2(int n) {
        
        int [] data = new int[n+1];
        
        // Create the initial dataset
        // skip over 0 and 1
        for (int i = 2; i <= n; i++) {
            data[i] = i;
        }
        System.out.println("Our initial list = " + Arrays.toString(data));
        
        int index = 2;
        int candidate;
               
        while(index <= n) {
            System.out.println("Index = " + index);
            candidate = data[index];
            if (0 == candidate) {
                index++;
                continue;
            }
            if(candidate * candidate > (n+1)) {
                System.out.println("All done");
                break;
            }
            
            System.out.println("cand = " + candidate);
            // picked candidate
            int candidate_index = index + candidate;
            //System.out.println("candidate_index = "+ candidate_index);
            //mult = cand;
            //System.out.println("Mult = " + mult);
            System.out.println("index2 = " + candidate_index);
            while ((candidate_index <= n)) {
                if (0 != data[candidate_index]) {
                    data[candidate_index] = 0;
                }
               candidate_index += candidate;
               System.out.println(">>index2 = " + candidate_index);
            }
            index++;                        
        }
        System.out.println("Final = " + Arrays.toString(data));                
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Eratosthenes e = new Eratosthenes();
        e.sieve1(26);        
        e.sieve2(26);
        
    }
                
    
}

@@ -1147,17 +1147,16 @@
 thenes;%0A
-%0A
 import j
@@ -1173,65 +1173,11 @@
 rray
-List;%0Aimport java.util.Arrays;%0Aimport java.util.Iterator;
+s;%0A
 %0A%0A/*
@@ -1242,167 +1242,8 @@
    %0A
-    /*%0A    * Pick candidate%0A    * Start eliminating multiple of candidates until we are at n%0A    * pick next available candidate%0A    * rinse and repeat%0A    */%0A
     
@@ -1259,17 +1259,16 @@
 id sieve
-1
 (int n) 
@@ -1273,1296 +1273,8 @@
 ) %7B%0A
-        %0A        int %5B%5D data = new int%5Bn+1%5D;%0A        %0A        // Create the initial dataset%0A        // skip over 0 and 1%0A        for (int i = 2; i %3C= n; i++) %7B%0A            data%5Bi%5D = i;%0A        %7D%0A        System.out.println(%22Our initial list = %22 + Arrays.toString(data));%0A        %0A        int index = 2;%0A        int candidate;%0A               %0A        while(index %3C= n) %7B%0A            candidate = data%5Bindex%5D;%0A            if (0 == candidate) %7B%0A                index++;%0A                continue;%0A            %7D%0A            %0A            System.out.println(%22cand = %22 + candidate);%0A            // picked candidate%0A            int candidate_index = index + candidate;%0A            //System.out.println(%22candidate_index = %22+ candidate_index);%0A            //mult = cand;%0A            //System.out.println(%22Mult = %22 + mult);%0A            %0A            while ((candidate_index %3C= n) && (data%5Bcandidate_index%5D %3C= n) && (0 != data%5Bcandidate_index%5D)) %7B%0A               data%5Bcandidate_index%5D = 0;%0A               candidate_index += candidate;%0A               System.out.println(%22%3E%3Eindex2 = %22 + candidate_index);%0A            %7D%0A            index++;                        %0A        %7D%0A        System.out.println(%22Final = %22 + Arrays.toString(data));                %0A    %7D%0A    %0A    public void sieve2(int n) %7B%0A        %0A
     
@@ -1905,41 +1905,89 @@
 ln(%22
-All done%22);%0A                break
+Stopping now since all %22%0A                        + %22remaining numbers are prime%22)
 ;%0A  
@@ -1988,33 +1988,42 @@
 %22);%0A            
-%7D
+    break;
 %0A            %0A  
@@ -2019,29 +2019,26 @@
         
+%7D
 %0A
-    
         
 System.o
@@ -2033,50 +2033,12 @@
     
-System.out.println(%22cand = %22 + candidate);
+    
 %0A   
@@ -2082,35 +2082,41 @@
     
-int candidate_index = index
+System.out.println(%22candidate = %22
  + c
@@ -2115,32 +2115,33 @@
  = %22 + candidate
+)
 ;%0A            //
@@ -2138,38 +2138,20 @@
         
-//System.out.println(%22
+int 
 candidat
@@ -2160,17 +2160,22 @@
 index = 
-%22
+index 
 + candid
@@ -2181,93 +2181,81 @@
 date
-_index);%0A            //mult = cand;%0A            //System.out.println(%22Mult = %22 + mult
+;%0A            System.out.println(%22Zero out all multiples of %22 + candidate
 );%0A 
@@ -2285,22 +2285,31 @@
 rintln(%22
+candidate_
 index
-2
  = %22 + c
@@ -2317,32 +2317,45 @@
 ndidate_index);%0A
+            %0A
             whil
@@ -2582,16 +2582,23 @@
 ln(%22
-%3E%3E
+candidate_
 index
-2
  = %22
@@ -2949,42 +2949,11 @@
 ieve
-1(26);        %0A        e.sieve2(26
+(30
 );%0A 

clean up code and remove old func