Largest proper divisor of n: Difference between revisions

→‎{{header|AppleScript}}: Corrected to make the result for 1 a task requirement rather than 1's largest proper divisor.
(→‎{{header|AppleScript}}: Corrected to make the result for 1 a task requirement rather than 1's largest proper divisor.)
Line 75:
 
<lang applescript>on largestProperDivisor(n)
if (n mod 2 = 0) then return n div 2
if (n mod 3 = 0) then return n div 23
else if (n mod< 3 = 05) then return missing value
repeat with i from return5 to (n ^ 0.5 div 31) by 6
if (n mod i = 0) then return n div i
else
repeatif with(n mod (i from+ 52) to= (n0) ^then 0.5return n div 1)(i by+ 62)
end repeat
if (n mod i = 0) then return n div i
return 1
if (n mod (i + 2) = 0) then return n div (i + 2)
end repeat
return 1
end if
end largestProperDivisor
 
on task(min, max)
script o
property LPDs : {}
Line 95 ⟶ 92:
set w to (count (max as text)) * 2 + 3
set padding to text 1 thru (w - (count (min as text)) * 2) of " "
set end of o's LPDs to "1:1" & padding
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set c to 01
repeat with n from min2 to max
set end of o's LPDs to text 1 thru w of ((n as text) & ":" & largestProperDivisor(n) & padding)
set c to c + 1
Line 115 ⟶ 113:
end task
 
task(1, 100)</lang>
 
{{output}}
557

edits