Largest proper divisor of n: Difference between revisions
Content added Content deleted
(→{{header|AppleScript}}: Corrected to make the result for 1 a task requirement rather than 1's largest proper divisor.) |
|||
Line 75: | Line 75: | ||
<lang applescript>on largestProperDivisor(n) |
<lang applescript>on largestProperDivisor(n) |
||
if (n mod 2 = 0) then |
if (n mod 2 = 0) then return n div 2 |
||
return n div |
if (n mod 3 = 0) then return n div 3 |
||
if (n < 5) then return missing value |
|||
repeat with i from 5 to (n ^ 0.5 div 1) by 6 |
|||
⚫ | |||
else |
|||
if (n mod (i + 2) = 0) then return n div (i + 2) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if (n mod (i + 2) = 0) then return n div (i + 2) |
|||
⚫ | |||
⚫ | |||
end if |
|||
end largestProperDivisor |
end largestProperDivisor |
||
on task( |
on task(max) |
||
script o |
script o |
||
property LPDs : {} |
property LPDs : {} |
||
Line 95: | Line 92: | ||
set w to (count (max as text)) * 2 + 3 |
set w to (count (max as text)) * 2 + 3 |
||
set padding to text 1 thru (w - |
set padding to text 1 thru (w - 2) of " " |
||
set end of o's LPDs to "1:1" & padding |
|||
set astid to AppleScript's text item delimiters |
set astid to AppleScript's text item delimiters |
||
set AppleScript's text item delimiters to "" |
set AppleScript's text item delimiters to "" |
||
set c to |
set c to 1 |
||
repeat with n from |
repeat with n from 2 to max |
||
set end of o's LPDs to text 1 thru w of ((n as text) & ":" & largestProperDivisor(n) & padding) |
set end of o's LPDs to text 1 thru w of ((n as text) & ":" & largestProperDivisor(n) & padding) |
||
set c to c + 1 |
set c to c + 1 |
||
Line 115: | Line 113: | ||
end task |
end task |
||
task( |
task(100)</lang> |
||
{{output}} |
{{output}} |