Created
February 12, 2012 20:48
-
-
Save jpoetker/1810787 to your computer and use it in GitHub Desktop.
Embedly Zipf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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