Narcissistic decimal number: Difference between revisions
m
→{{header|AppleScript}}: Idiomatic: minor optimisation, rewritten preamble.
m (→{{header|AppleScript}}: Idiomatic version rewritten with more efficient digit group generation.) |
m (→{{header|AppleScript}}: Idiomatic: minor optimisation, rewritten preamble.) |
||
Line 432:
===Idiomatic===
<lang applescript>(*
Line 443 ⟶ 441:
script o
property output : {}
property listOfDigits : missing value
property m : 0 -- Digits per collection/number.
property done : false
Line 451 ⟶ 450:
-- Otherwise continue branching the recursion to derive longer lists.
if (digitShortfall is 0) then
-- Assign the list to a script property to allow faster references to its items (ie. incl. reference to script).
set listOfDigits to digitList
set temp to sumOfPowers
set unmatched to m
Line 457 ⟶ 458:
if (sumDigit is in digitList) then
repeat with d from 1 to unmatched
if (sumDigit = number d of
set number d of
set unmatched to unmatched - 1
exit repeat
Line 486 ⟶ 487:
end script
(*
if (q > 89) then set q to 89 -- Number of narcissistic decimal integers known to exist.
set maxM to 16 -- Maximum number of decimal digits (other than trailing zeros) in AppleScript numbers.
tell o
-- Begin with zero, which is narcissistic by definition and is never the only digit used in other numbers.
|