Narcissistic decimal number: Difference between revisions
→{{header|AppleScript}}: Natively written version: two further optimisations, giving a 16%-18% speed improvement. Burb updated with new timings.
(→AppleScript :: Functional: Misleading. ( 'native' means without import)) |
(→{{header|AppleScript}}: Natively written version: two further optimisations, giving a 16%-18% speed improvement. Burb updated with new timings.) |
||
Line 426:
<lang AppleScript>{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}</lang>
===
AppleScript can certainly struggle when the code's an impenetrable and inefficient pidgin trying to be two other languages. However, when tested in 2020 on an apparently faster machine, the script above only takes 7.9 minutes to return 25 numbers. On the same machine, the natively written offering below returns the same result in just under
<lang applescript>use sorter : script "Insertion Sort" -- <https://www.rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#AppleScript>
Line 461:
-- Each group in the old list is the basis for new ones containing an additional digit each.
set oldGroup to item i of o's previousDigitGroups
set
repeat with thisDigit in
-- Create and test the new groups.
repeat with addedDigit from end of oldGroup to 9
-- Store each new group and calculate its potential narcissistic integer value.
set end of o's newDigitGroups to newGroup
▲ set n to 0
▲ set n to n + thisDigit ^ m
▲ end repeat
-- Extract the integer's digits and sort them numerically.
set checkGroup to {}
|