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 smallestlowest possible value of n in this respect is 123. 6But timesfor thata isnumber 738,beginning whichwith still1 doesn'tto fitstand theany bill,chance butof youcontaining havethe tosame startdigits somewhere.as 'Steps'both are thea number of 'nthat's actually2 triedtimes whenit nand *another that's 6 doesn'ttimes exceedit, theit nextmust poweralso ofcontain 10.at Whileleast noone powerdigit ofthat's 10no isless exactlythan divisible2 byand 6, itanother that''is''s technicallyno theless pointthan at6. whichThe thelowest numbercombination of digitsthese increasesis 26, sowhich I'vealso pedanticallyproduces adjusteda themultiple logicof to3 reflectwhen this.added to :)a power Theof number10. ofSo stepsthis betweenmakes 100,000a andslightly thebetter finalpost-power arrivalstart atpoint than 1422,857 issaving 14,286,eight whichsteps isper interestingpower. ;)
 
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 {{}, 123126, 1000, 0}
repeat
if (n * 6 < n10) then
Line 51 ⟶ 54:
else
set end of output to "Nothing below " & n10 & (" (" & steps & " steps)")
set n to n10 + 226 -- set n to n10 * 1.26 as integer
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 100001000 (23714 steps)
Nothing below 10000010000 (2459228 steps)
Nothing below n = 142857100000 (167452442 steps altogether)
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':
<lang applescript>"Nothing below 1000 (1514 steps)
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}}==
557

edits