Jump to content

Arithmetic derivative: Difference between revisions

m
→‎{{header|Perl}}: avoid special-case for zero
m (→‎{{header|Perl}}: avoid special-case for zero)
Line 238:
use bigint;
no warnings 'uninitialized';
use List::Util <sum 'max>';
use ntheory 'factor';
 
Line 244:
 
sub D ($n) {
my (%f, $s);
return$f{$_}++ 0for iffactor max 1, my $nnabs == 0abs $n;
map { $s += $nabs * $f{$_}++ for factor (my/ $nabs_ =} abskeys $n)%f;
my $s = sum map { $nabs * $f{$_} / $_ } keys %f;
$n > 0 ? $s : -$s;
}
2,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.