Skip to content

Instantly share code, notes, and snippets.

@jpoetker
Created February 12, 2012 20:48
Show Gist options
  • Save jpoetker/1810787 to your computer and use it in GitHub Desktop.
Save jpoetker/1810787 to your computer and use it in GitHub Desktop.
Embedly Zipf
public class Zipf {
public static void main(String args[]) {
long totalWords = 0;
for(int i=1; i<=900; i++) {
totalWords += 2520/i;
}
System.out.println("Total words in text: " + totalWords);
long halfWords = totalWords/2;
System.out.println("Half of the words in text: " + halfWords);
totalWords = 0;
for(int i=1; i<=900; i++) {
totalWords += 2520/i;
System.out.println("" + i + ": " + totalWords);
if (totalWords > halfWords) {
System.out.println("unique words making up half of text: " + i);
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment