Colorful numbers: Difference between revisions

m
→‎{{header|AppleScript}}: Minor improvements.
m (→‎{{header|AppleScript}}: Minor improvements.)
Line 95:
=={{header|AppleScript}}==
<syntaxhighlight lang="applescript">(*
TheThis observes the task requirement that colorful numbers be identified using a test handler is observed,
here, but uses the information regarding 1s and 0s is used along withand some logic to skip obvious non-starters
non-starters and sparesave a few minutes' running time. Since multiplication is commutative, every number's
the "colorful" status of any number is matchedthe bysame that ofas its reverse's. Working up from 0, the lower number of each
the lower number of eachmirrored colorful pair is encounteredmet first and testingits atreverse thatderived. magnitudeIf the largest reversed number
obtained so far is actually reached, it's the last colorful number at that magnitude. The
must continue at least as far as the other. If the largest reversal of a colorful number
calculatedsearch soeither farend isthere actuallyor reached,jumps it'sto the last colorfullowest number worth trying at thatthe next magnitudelevel.
Testing either jumps to the first possibility at the next level or stops there.
*)
on isColorful(n)
Line 138 ⟶ 137:
set counter to 0
set counts to {}
set magnitude to 1 -- Number10 ^ (number of digits in tested- numbers1).
set resumptionCoeff to 2.3456789 -- Governs where to resume after a magnitude increase.
set searchLimit to 98765432 -- Highest number possible with the allowed digits.
set largestReverse to 9 -- Largest reverse of a single-digit number!
set n to -10
repeat
if ((n mod 10 > 1) or (magnitude < 2)) and (isColorful(n)) then
-- Check numbers not ending with 1 or 0 and all numbers < 100
-- (to show isColorful() working in all cases).
if ((n mod 10 > 1) or (magnitude < 2)) and (isColorful(n)) then
if (n < 100) then set end of colorfuls to text -3 thru -1 of (" " & n)
set counter to counter + 1
Line 153 ⟶ 148:
set counter to 0
set magnitude to magnitude * 10
if (magnitude > searchLimit98765432) then exit repeat
set n to resumptionCoeff2.3456789 * magnitude div 1 - 1
else
set temp to n
Line 165 ⟶ 160:
end if
end if
setif (n tomod n10 = +9) 1then
set n to n + 3
else
set n to n + 1
end if
end repeat
557

edits