Permuted multiples: Difference between revisions
→{{header|AppleScript}}: Further optimisation(s).
(→{{header|AppleScript}}: Further optimisation(s).) |
|||
Line 9:
=={{header|AppleScript}}==
{{trans|Phix}} — except that the 'steps' figure here is cumulative. Also, for six different numbers to have the same digits, each must have at least three digits, none of which can be 0. So the
Shifting the 26 up against the 1 obviously keeps the "at least" condition satisfied for longer during the subsequent additions of 3 at the low end and gives a start point much closer to the next power. This more than halves the number of steps performed and thus the time taken. It also produces the correct result(s), but I can't see that it's logically bound to do so. :\
<lang applescript>use AppleScript version "2.3.1" -- Mac OS X 10.9 (Mavericks) or later.
use sorter : script "Insertion Sort" -- <https://www.rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#AppleScript>
Line 32 ⟶ 35:
on task()
set {output, n, n10, steps} to {{},
repeat
if (n * 6 < n10) then
Line 51 ⟶ 54:
else
set end of output to "Nothing below " & n10 & (" (" & steps & " steps)")
set n to n10 +
set n10 to n10 * 10
-- set steps to 0
Line 68 ⟶ 71:
{{output}}
Using 'set n to n10 + 26':
<lang applescript>"Nothing below 1000 (15 steps)▼
<lang applescript>"Nothing below
Nothing below
Nothing below
n = 142857 (16720 steps altogether)
2 * n = 285714
3 * n = 428571
Line 77 ⟶ 81:
5 * n = 714285
6 * n = 857142"</lang>
{{output}}
Using 'set n to n10 * 1.26 as integer':
Nothing below 10000 (150 steps)
Nothing below 100000 (1506 steps)
n = 142857 (7126 steps altogether)
2 * n = 285714
3 * n = 428571
4 * n = 571428
5 * n = 714285
6 * n = 857142"
</lang>
=={{header|Factor}}==
|