Largest proper divisor of n: Difference between revisions

Added AppleScript.
m (→‎{{header|REXX}}: corrected a typo.)
(Added AppleScript.)
Line 70:
27 41 1 42 17 43 29 44 1 45
13 46 31 47 19 48 1 49 33 50</pre>
 
=={{header|AppleScript}}==
Most of this code is just to prepare the output for display. :D
 
<lang applescript>on largestProperDivisor(n)
if (n mod 2 = 0) then
return n div 2
else if (n mod 3 = 0) then
return n div 3
else
repeat with i from 5 to (n ^ 0.5 div 1) by 6
if (n mod i = 0) then return n div i
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 : {}
property output : {}
end script
set w to (count (max as text)) * 2 + 3
set padding to text 1 thru (w - (count (min as text)) * 2) of " "
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set c to 0
repeat with n from min 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
if (c mod 10 is 0) then
set end of o's output to o's LPDs as text
set o's LPDs to {}
end if
end repeat
if (c mod 10 > 0) then set end of o's output to o's LPDs as text
set AppleScript's text item delimiters to linefeed
set o's output to o's output as text
set AppleScript's text item delimiters to astid
return o's output
end task
 
task(1, 100)</lang>
 
{{output}}
<lang applescript>"1:1 2:1 3:1 4:2 5:1 6:3 7:1 8:4 9:3 10:5
11:1 12:6 13:1 14:7 15:5 16:8 17:1 18:9 19:1 20:10
21:7 22:11 23:1 24:12 25:5 26:13 27:9 28:14 29:1 30:15
31:1 32:16 33:11 34:17 35:7 36:18 37:1 38:19 39:13 40:20
41:1 42:21 43:1 44:22 45:15 46:23 47:1 48:24 49:7 50:25
51:17 52:26 53:1 54:27 55:11 56:28 57:19 58:29 59:1 60:30
61:1 62:31 63:21 64:32 65:13 66:33 67:1 68:34 69:23 70:35
71:1 72:36 73:1 74:37 75:25 76:38 77:11 78:39 79:1 80:40
81:27 82:41 83:1 84:42 85:17 86:43 87:29 88:44 89:1 90:45
91:13 92:46 93:31 94:47 95:19 96:48 97:1 98:49 99:33 100:50 "</lang>
 
=={{header|BASIC}}==
557

edits