Viewing a single comment thread. View all comments

registrant wrote

In perl 6:

sub factor(Int $i){

if $i == 2 {
    say 2;
    return;
}
if $i == 3 {
    say 3;
    return;
}

return if $i == 1;

for 2..$i.sqrt {
    if $i %% $_ { #found a factor
      say $_;
      factor Int($i/$_);
      return;
    }
}
say $i;

}

1