Skip to content

Instantly share code, notes, and snippets.

@jottinger
Created September 18, 2014 13:47
Show Gist options
  • Save jottinger/92feb42c4992377419f6 to your computer and use it in GitHub Desktop.
Save jottinger/92feb42c4992377419f6 to your computer and use it in GitHub Desktop.
Nepherus' homework, except it won't help since I used java collections, because it's java
public class Iterate {
public static void main(String[] args) {
new Iterate().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;
BitSet bits=new BitSet();
while(scanner.hasNext()) {
int i=scanner.nextInt();
bits.set(i);
counter++;
}
for (int i = bits.nextClearBit(999999); i >= 0; i = bits.nextSetBit(i+1)) {
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