Hacker News new | past | comments | ask | show | jobs | submit login

Yeah, its a sieve, this block:

  foreach (@k){
  	my $b = $_;
  	my $n = "1";
  	$c=1;
  	next if ($b >= floor(sqrt($y + 1)));
  	for ($count = $y + 1 ;$count >= $c; $n++){
  		$c = (((3 * $n) - (0.5 * cos($pi*$n))) + 1.5) * $b;
  		next unless ($c <= $y + 1);
  		push (@c, $c);
  	}
  }
Allows you to iterate of the next set and find the none prime and remove them from the SET of 1/2 (6 n-cos(pi n)+3) Thats how a sieve works. 1/2 (6 n-cos(pi n)+3) is only good up to n^2 then you need to multiply 1/2 (6 n-cos(pi n)+3) by i as you noted the first non-prime result was @ 5^2 therefore you need to sieve the rest of the numbers up to 7^2 by doing (1/2 (6 n-cos(pi n)+3)) * 5 Then after 7^2 seive off with (1/2 (6 n-cos(pi n)+3)) * 7 you continue to repeat this for all numbers in the original set. See the sieve of eratosthenes. Mine though shows primes as a set of sin waves kind of like what the op has. As a matter of fact the post is basically a visual representation of what I coded above.



Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: