Skip to content

Instantly share code, notes, and snippets.

Created February 11, 2012 01:00
Show Gist options
  • Save anonymous/1794764 to your computer and use it in GitHub Desktop.
Save anonymous/1794764 to your computer and use it in GitHub Desktop.
Number Of Unique Words In Half The Text
<?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