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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.