Jump to content

Parse Error in Sieve of Eratosthenes


sam06

Recommended Posts

Any idea why I'm getting "parse error" for this on the echo implode... line?

 

 

<?php
$c = 50000;
$m = (int)((sqrt($c))+1);
$p = array_fill(2, $c-1, 1);
$i = 2;
while ($i<$m) {
$j=$i*2;
while($j<$c+1) {
$p[$j] = 0;
$j += $i;
}
$i++;
}
echo implode(’ ‘,array_keys($p, 1));
?>

 

Many thanks.

Sam

Link to comment
https://forums.phpfreaks.com/topic/170618-parse-error-in-sieve-of-eratosthenes/
Share on other sites

It looks like your using some sort of non-standard quotes...

 

<?php
$c = 50000;
$m = (int)((sqrt($c))+1);
$p = array_fill(2, $c-1, 1);
$i = 2;
while ($i<$m) {
    $j=$i*2;
    while($j<$c+1) {
        $p[$j] = 0;
        $j += $i;
    }
    $i++;
}
echo implode(' ',array_keys($p, 1));
?>

 

Are you using M$ Word or OpenOffice as a text editor? They tend to make your printed documents prettier by replacing quotes with special ones. For coding I would suggest using something like Notepad++ -> http://notepad-plus.sourceforge.net/uk/site.htm

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.