I thought Monks might like to come up with a shorter version?#!/usr/bin/perl use strict; use warnings; $\ = $/; my %not_prime = (); my $limit = 100; # change this to $ARGV[0] if required foreach my $x ( 2 .. $limit ) { # for all numbers 2 to the maximum required next if $not_prime{$x}; # skip numbers already known not prime print "current prime is $x"; my $y = $x; while ( ($x + $y) <= $limit ) { print " * crossing off " . ($x + $y) . ", a multiple of $x"; $not_prime{ $x + $y } = 1; $y += $x; } } print "Primes between 2 and $limit:"; for ( 2 .. $limit ) { unless ( $not_prime{$_} ) { print "$_"; } }
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print
In reply to Sieve of Eratosthenes Golf? by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |