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 -- InitialStarting with palindromes in the hundreds will have an odd number of digits.
set baseHi to endDigit * 10 -- InitialNumber formed from just the "high end" valuedigits, (currentinitially end digitendDigit and a "middle" digit of 0).
set hi to baseHi
set carryCheck to hi + 10 -- ValueNumber reached when incrementing the "high end" number changes its first digit.
set inc to 10 -- Incrementor for the middle digit(s) of the palindromes themselves.
set counter to 0
repeatset untilmaxNeeded (counter =to 1000)
set hidone to hi + 1false
-- Make a palindrome from the current high-end value, not repeating the "middle" digit in oddDigitCount mode.
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
-- IfCheck the palindrome's gapfulresult and isthe onefollowing of9 thosepalindromes required,(derived addby it as text toincrementing the appropriatemiddle collection.digit(s))
-- and store as text any which are both gapful and the ones required.
if (pal mod outerNumber is 0) then
repeat 10 set counter to counter + 1times
if (counterpal mod 20outerNumber is 0) then
set endcounter ofto collector1counter to+ intText(pal)1
else if (counter < 8620) then
else if (counter 100) then set end of collector1 to intText(pal)
setelse endif of(counter collector2< to intText(pal86) then
else if (counter < 991100) then
else -- if (counter 1000) then set end of collector2 to intText(pal)
setelse endif of(counter collector3< to intText(pal991) then
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 if set pal to pal + inc
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
-- IncrementIf the high-end value. Ifa thiscarry changes its first digit, reset for longer palindromes.
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
557

edits