Narcissistic decimal number: Difference between revisions

→‎JS ES6: updated output
(→‎{{header|AppleScript}}: Slightly faster version, plus timings of full/partial searches)
(→‎JS ES6: updated output)
Line 1,581:
// Do the decimal digits of N, each raised to the power E, sum to N itself ?
 
// isDaffodil :: Int -> Int -> Bool
const isDaffodil = (e, n) => {
const
powerSum = (n, xs) => xs.reduce((a, x) => a + Math.pow(x, n), 0),
digitList = n => (n > 0) ? (
cons((n % 10), digitList(Math.floor(n / 10)))
) : [],
ds = digitList(n);
return e === ds.length && n === powerSum(e, ds);
};
 
// The subset of integers of n digits that actually need daffodil checking:
Line 1,673:
 
return show(
//digitPowerSums(3)
concatMap(narcissiOfLength, enumFromTo(0, 7))
);
Line 1,679 ⟶ 1,680:
(Tested in Atom editor, using Script package)
<pre>[0,1,2,3,4,5,6,7,8,9,153,370,371,407,1634,8208,9474,54748,92727,93084,548834,1741725,4210818,9800817,9926315]
[Finished in 0.121s118s]</pre>
 
=={{header|jq}}==
9,655

edits