Arithmetic derivative: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 39:
=={{header|C++}}==
{{libheader|Boost}}
<syntaxhighlight lang="cpp">#include <iomanip>
#include <iostream>
 
Line 140:
Using ''float64'' (finessed a little) to avoid the unpleasantness of ''math/big'' for the stretch goal.
Assumes that ''int'' type is 64 bit.
<syntaxhighlight lang="go">package main
 
import (
Line 233:
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import Control.Monad (forM_)
import Data.List (intercalate)
import Data.List.Split (chunksOf)
Line 313:
=={{header|J}}==
Implementation:
<syntaxhighlight lang=J"j">D=: {{ +/y%q:1>.|y }}"0</syntaxhighlight>
 
In other words: find the sum of the argument divided by each of the sequence of prime factors of its absolute value (with a special case for zero -- we use the maximum of either 1 or that absolute value when finding the sequence of prime factors).
Line 319:
Task example:
 
<syntaxhighlight lang=J"j"> D _99+i.20 10
_75 _77 _1 _272 _24 _49 _34 _96 _20 _123
_1 _140 _32 _45 _22 _124 _1 _43 _108 _176
Line 343:
Also, it seems like it's worth verifying that order of evaluation does not create an ambiguity for the value of D:
 
<syntaxhighlight lang=J"j"> 15 10 6 + 2 3 5 * D 15 10 6
31 31 31</syntaxhighlight>
 
Stretch task:
 
<syntaxhighlight lang="j"> (D 10x^1+i.4 5)%7
1 20 300 4000 50000
600000 7000000 80000000 900000000 10000000000
Line 355:
 
=={{header|Julia}}==
<syntaxhighlight lang="ruby">using Primes
 
D(n) = n < 0 ? -D(-n) : n < 2 ? zero(n) : isprime(n) ? one(n) : typeof(n)(sum(e * n ÷ p for (p, e) in eachfactor(n)))
Line 413:
{{trans|J}}
{{libheader|ntheory}}
<syntaxhighlight lang="perl">use v5.36;
use bigint;
no warnings 'uninitialized';
Line 475:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 563:
 
=={{header|Python}}==
<syntaxhighlight lang="python">from sympy.ntheory import factorint
 
def D(n):
Line 629:
 
=={{header|Raku}}==
<syntaxhighlight lang=perl6"raku" line>use Prime::Factor;
 
multi D (0) { 0 }
Line 690:
{{libheader|Wren-fmt}}
As integer arithmetic in Wren is inaccurate above 2^53 we need to use BigInt here.
<syntaxhighlight lang="ecmascript">import "./big" for BigInt
import "./fmt" for Fmt
 
10,327

edits