Permuted multiples: Difference between revisions

Content added Content deleted
(Added AppleScript.)
(→‎{{header|AppleScript}}: Woke up realising that six permutations of the same digits requires the numbers to have at least three digits each.)
Line 9: Line 9:


=={{header|AppleScript}}==
=={{header|AppleScript}}==
{{trans|Phix}} — except that the 'steps' figure here is cumulative. 'Steps' are the number of 'n's actually tried when n * 6 doesn't exceed the next power of 10. While no power of 10 is exactly divisible by 6, it ''is'' technically the point at which the number of digits increases, so I've pedantically adjusted the logic to reflect this. :) The number of steps between 100,000 and the final arrival at 142,857 is 14,286, which is interesting.
{{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 smallest possible value of n is 123. 'Steps' are the number of 'n's actually tried when n * 6 doesn't exceed the next power of 10. While no power of 10 is exactly divisible by 6, it ''is'' technically the point at which the number of digits increases, so I've pedantically adjusted the logic to reflect this. :) The number of steps between 100,000 and the final arrival at 142,857 is 14,286, which is interesting.
<lang applescript>use AppleScript version "2.3.1" -- Mac OS X 10.9 (Mavericks) or later.
<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>
use sorter : script "Insertion Sort" -- <https://www.rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#AppleScript>
Line 32: Line 32:


on task()
on task()
set {output, n, n10, steps} to {{}, 3, 10, 0}
set {output, n, n10, steps} to {{}, 123, 1000, 0}
repeat
repeat
if (n * 6 < n10) then
if (n * 6 < n10) then
Line 68: Line 68:


{{output}}
{{output}}
<lang applescript>"Nothing below 10 (0 steps)
<lang applescript>"Nothing below 1000 (15 steps)
Nothing below 100 (2 steps)
Nothing below 10000 (237 steps)
Nothing below 1000 (24 steps)
Nothing below 100000 (2459 steps)
Nothing below 10000 (246 steps)
n = 142857 (16745 steps altogether)
Nothing below 100000 (2468 steps)
n = 142857 (16754 steps altogether)
2 * n = 285714
2 * n = 285714
3 * n = 428571
3 * n = 428571