Narcissistic decimal number: Difference between revisions

→‎{{header|AppleScript}}: Minor modification to natively written version to match change to recommended sort.
(→‎{{header|AppleScript}}: Natively written version: previous speed slightly more than doubled, limit on number of digits attempted, improved comments.)
(→‎{{header|AppleScript}}: Minor modification to natively written version to match change to recommended sort.)
Line 426:
{{Out}}
<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>
----
 
===Natively written===
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 finds the same 25 numbers in around 0.22 seconds. It uses the optimisation approach alluded to above. But this doesn't necessarily find numbers of the same width in numerical order, so all narcissistic numbers with the same number of digits have to be found before their order can be determined. Thus it takes about the same amount of time (12.9 seconds) to find the first 34 numbers as it does the first 41, the 34th to 41st numbers all having 11 digits. Nearly four and a quarter minutes are needed for the first 42 numbers and nearly an hour for the first 44. The highest narcissistic integer AppleScript can represent ''as'' an integer is the 31st in the table on the Discussion page. The highest that can be accurately displayed as a real is the 43rd, although the 44th seems to be accurate internally. For this reason, the 44th is effectively the highest narcissistic decimal number the script can identify. As per the task description, the first so many numbers are returned rather than the numbers whose digit counts fall within a specified range.
Line 507:
end repeat
-- Sort the collected narcissistic numbers.
tell sorter to insertionSortsort(o's output, 1, -1)
-- If q wasn't reached, it's because the limit of precision of AppleScript reals was.
if (counter < q) then
557

edits