Narcissistic decimal number: Difference between revisions
m
→JS :: Reduced search (unordered digit combinations): Tidying
(→JS :: Reduced search: Updated primitives and output.) |
|||
Line 2,267:
// narcissiOfLength :: Int -> [Int]
const narcissiOfLength = n =>
digitPowerSums(n)
) : [0];
// powerSum :: Int -> [Int] -> Int
const powerSum = n =>
Line 2,276 ⟶ 2,283:
// True if the decimal digits of N,
// each raised to the power E, sum to N.
const ds = digitList(n);
return e === ds.length
▲ xs.reduce((a, x) => a + Math.pow(x, n), 0),
digitList = n => 0 < n ? (▼
cons(n % 10)(▼
digitList(Math.floor(n / 10))▼
▲ )
▲ ) : [],
};
Line 2,331 ⟶ 2,330:
const cons = x =>
xs => [x].concat(xs);
// digitList :: Int -> [Int]
) : [];
// filter :: (a -> Bool) -> [a] -> [a]
|