Palindromic gapful numbers: Difference between revisions
→{{header|AppleScript}}: 9 out of 10 palindromes now derived directly from incrementation of middle digit(s). 3.4 times as fast as before.
(→{{header|AppleScript}}: 9 out of 10 palindromes now derived directly from incrementation of middle digit(s). 3.4 times as fast as before.) |
|||
Line 66:
set {collector1, collector2, collector3} to {{}, {}, {}}
set outerNumber to endDigit * 11 -- Number formed from the palindromes' first and last digits.
set oddDigitCount to true --
set baseHi to endDigit * 10 --
set hi to baseHi
set carryCheck to hi + 10 --
set inc to 10 -- Incrementor for the middle digit(s) of the palindromes themselves.
set counter to 0
repeat until (done)
-- Work out every 10th palindrome (middle digit = 0) from the current "high end" number.
set pal to hi
if (oddDigitCount) then
Line 83 ⟶ 86:
set temp to temp div 10
end repeat
--
-- and store as text any which are both gapful and the ones required.
repeat 10
if (
set
else if (counter
else --if (counter ≤ 1000) then
set end of collector3 to intText(pal)
set done to (counter = maxNeeded)
if (done) then exit repeat
end if
end if
end repeat
-- Increment the high-end value. If this changes its first digit, reset for longer palindromes.▼
-- Increment the high end number's penultimate digit after every 10th palindrome.
▲ set hi to hi + 1
▲ --
set hi to hi + 10
if (hi = carryCheck) then
set oddDigitCount to (not oddDigitCount)
Line 103 ⟶ 113:
set baseHi to baseHi * 10
set carryCheck to carryCheck * 10
set inc to inc div 11 * 10
else
set inc to inc * 11
end if
set hi to baseHi
|