$bestPBScore[$i] && !$done)
{
$oldPBScore = $bestPBScore[$i];
$oldPB = $bestPB[$i];
$bestPBScore[$i] = $pbCandidateScore;
$bestPB[$i] = $pbCandidate;
ExaminePowerBallCount($oldPB, $oldPBScore);
$done = 1;
}
}
}
function ExamineRegularBallCount($rbCandidate, $rbCandidateScore)
{
global $bestRB, $bestRBScore;
$done = 0;
for($i = 0; $i <= 9; $i++)
{
if($rbCandidateScore > $bestRBScore[$i] && !$done)
{
$oldRBScore = $bestRBScore[$i];
$oldRB = $bestRB[$i];
$bestRBScore[$i] = $rbCandidateScore;
$bestRB[$i] = $rbCandidate;
ExamineRegularBallCount($oldRB, $oldRBScore);
$done = 1;
}
}
}
//!!!CHANGE ALERT!!!
//open the file -- note URL can change at any time!
$fileStuff = file("http://www.powerball.com/powerball/winnums-text.txt");
//!!!CHANGE ALERT!!!
//-1 shouldn't work but it does, this can change
//count number of rows in file
$numRows = count($fileStuff) - 1;
//!!!CHANGE ALERT!!!
//go through first 10 rows to date check-- number of rows can change
for($i = 0; $i < 10; $i++)
{
//!!!CHANGE ALERT!!!
//look for first date in list-- number can change
if(strstr($fileStuff[$i], "11/05/1997"))
{
$rowStart = $i;
}
}
//get number of drawings
//i should add one to this, but we start rows with zero
$numDrawings = $numRows - $rowStart;
//init every powerball number with a zero
for($i = 0; $i <= 42; $i++)
{
$powerBall[$i] = 0;
}
//init every regball
for($i = 0; $i <= 10; $i++)
{
$regularBall[$i] = 0;
}
//go through each row and increment ball if it occurs
for($i = $rowStart; $i <= $numRows; $i++)
{
//get first space after the date
$spacePos = strpos($fileStuff[$i], " ");
$ballCount = 1;
for($currentPos = $spacePos + 1; $fileStuff[$i][$currentPos] > "\x18"; $currentPos++)
{
if($fileStuff[$i][$currentPos] == "\x20")
{
//do nothing
}
else
{
$newInt = $fileStuff[$i][$currentPos] . $fileStuff[$i][$currentPos + 1];
//settype to integer
settype($newInt, "integer");
if($ballCount == 6)
{
$powerBall[$newInt]++;
if($i == 1)
{
$savedPB = $newInt;
}
}
else
{
$regularBall[$newInt]++;
if($i == 1)
{
$savedRB[$ballCount] = $newInt;
}
}
$currentPos++;
$ballCount++;
}
}
}
//Write current drawings into a file
//Display Time
echo "There have been " . $numDrawings . " drawings.\n
\n
\n";
echo "The last drawing:\n
\n";
for($i = 1; $i <= 5; $i++)
{
echo $savedRB[$i] . " ";
}
echo "\n
\nwith Powerball:\n
\n";
echo $savedPB . "\n
\n";
//examine each regular ball for the best
for($i = 1; $i < count($regularBall); $i++)
{
ExamineRegularBallCount($i, CalculateRBScore($regularBall[$i]));
}
//examine each powerball for the best
for($i = 1; $i < count($powerBall); $i++)
{
ExaminePowerBallCount($i, CalculatePBScore($powerBall[$i]));
}
echo "
\n
\n