Created
February 11, 2012 01:00
-
-
Save anonymous/1794764 to your computer and use it in GitHub Desktop.
Number Of Unique Words In Half The Text
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
<?php | |
$num_unique_words = 900; | |
// how many unique words make up half the text? | |
$start = 2520; | |
$total_word_count = 0; | |
$word_count = 0; | |
for ($i = 1; $i <= $num_unique_words; $i++) | |
{ | |
$t = $start / $i; | |
echo 'word ' . $i . ' used ' . $t . ' times.' . "\n"; | |
$total_word_count += $t ; | |
} | |
for ($i = 1; $i <= $num_unique_words; $i++) | |
{ | |
$t = $start / $i; | |
echo 'word ' . $i . ' used ' . $t . ' times.' . "\n"; | |
$word_count += $t; | |
if ($word_count >= $total_word_count/2) | |
{ | |
echo 'done'; | |
break; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment