Skip to content

Instantly share code, notes, and snippets.

@jottinger
Created September 18, 2014 14:18
Show Gist options
  • Save jottinger/a7c104c6ed73a1154992 to your computer and use it in GitHub Desktop.
Save jottinger/a7c104c6ed73a1154992 to your computer and use it in GitHub Desktop.
Iterating using an array, because whatever school Nepherus goes to teaches NOTHING worthwhile, apparently
public class Iterate2 {
public static void main(String[] args) {
new Iterate2().run();
}
public void run() {
long start = System.currentTimeMillis();
InputStream in = this.getClass().getResourceAsStream("/numbers.txt");
BufferedInputStream bis = new BufferedInputStream(in);
Scanner scanner = new Scanner(bis);
int counter = 0;
boolean[] bits = new boolean[1100000];
while (scanner.hasNext()) {
int i = scanner.nextInt();
bits[i] = true;
counter++;
}
for (int i = 1000000; i < 1100000; i++) {
if (bits[i]) {
System.out.println(i);
}
}
long end = System.currentTimeMillis();
System.out.printf("%d entries processed in %d ms%n", counter, end - start);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment