perl.pl 678 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/perl
  2. =begin
  3. perl example code for Ace
  4. =cut
  5. use strict;
  6. use warnings;
  7. my $num_primes = 0;
  8. my @primes;
  9. # Put 2 as the first prime so we won't have an empty array
  10. $primes[$num_primes] = 2;
  11. $num_primes++;
  12. MAIN_LOOP:
  13. for my $number_to_check (3 .. 200)
  14. {
  15. for my $p (0 .. ($num_primes-1))
  16. {
  17. if ($number_to_check % $primes[$p] == 0)
  18. {
  19. next MAIN_LOOP;
  20. }
  21. }
  22. # If we reached this point it means $number_to_check is not
  23. # divisable by any prime number that came before it.
  24. $primes[$num_primes] = $number_to_check;
  25. $num_primes++;
  26. }
  27. for my $p (0 .. ($num_primes-1))
  28. {
  29. print $primes[$p], ", ";
  30. }
  31. print "\n";