Comments

You must log in or register to comment.

Cosine wrote

Believe it or not, GNU coreutils includes the factor program

$ factor 112
112: 2 2 2 2 7
4

zombie_berkman wrote

I beleieve I used BC to do this in college but I forget how I did it. Sorry

2

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