Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub prime {
- my $n = 1;
- my $out;
- sub {
- loop {
- $n++;
- my $is-prime = True;
- loop (my $i = 2; $i <= $n.sqrt; $i++) {
- if $n mod $i == 0 {
- $is-prime = False;
- last;
- }
- }
- if $is-prime {
- $out = $n;
- last;
- }
- }
- $out;
- }
- }
- my $p = prime();
- my @arr = (2, 3, 5, 7, 11, 13, 17, 19, 23);
- loop (my $i = 0; $i < @arr.elems; $i++) {
- $p() == @arr[$i] or die "Wrong value";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement