Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Challenge 41 Task 1
#perl 5.22.1 %isPrime=(2=>1,3=>1,5=>1,7=>1,11=>1); for (1..100){ primeFactors($_) } sub primeFactors{ my $wn=$number=shift; my @factorsList=(); my $test=2; $limit=sqrt($wn+1); while ($test < $limit){ if ($wn % $test){ $test++; } else{ push @factorsList,$test; $isPrime{$test}=1; $wn=$wn/$test; $limit=sqrt($wn+1) } } push @factorsList,$wn; if (scalar @factorsList == 1){ print "$number is prime\n"; $isPrime{$number}=1; } else{ print "$number :factors are ", join ",",@factorsList,($isPrime{scalar @factorsList})? "and is attractive\n":"\n" }; }
run
|
edit
|
history
|
help
0
testing anonymous routine dereference with alternate syntax
Price_supriya
Perl
Array_with_join_function
Challenge 41 Task 1
Hash
Perl
Hash-Nevil
test hello worl perl
Array_with_shift_function