Special divisors: Difference between revisions
Content added Content deleted
(added Pascal link to Delphi) |
(Added AppleScript.) |
||
Line 98: | Line 98: | ||
{{out}} |
{{out}} |
||
Same as the Algol 68 sample. |
Same as the Algol 68 sample. |
||
=={{header|AppleScript}}== |
|||
<lang applescript>on factors(n) |
|||
set output to {} |
|||
if (n > 0) then |
|||
set sqrt to n ^ 0.5 |
|||
set limit to sqrt div 1 |
|||
if (limit = sqrt) then |
|||
set end of output to limit |
|||
set limit to limit - 1 |
|||
end if |
|||
repeat with i from limit to 1 by -1 |
|||
if (n mod i is 0) then |
|||
set beginning of output to i |
|||
set end of output to n div i |
|||
end if |
|||
end repeat |
|||
end if |
|||
return output |
|||
end factors |
|||
on reversedIntVal(n, base) |
|||
set r to n mod base as integer |
|||
set n to n div base |
|||
repeat until (n = 0) |
|||
set r to r * base + n mod base |
|||
set n to n div base |
|||
end repeat |
|||
return r |
|||
end reversedIntVal |
|||
on hasSpecialDivisors(n, base) |
|||
set divisors to factors(n) |
|||
if (divisors is {}) then return false |
|||
set r to reversedIntVal(n, base) |
|||
repeat with d in divisors |
|||
if (r mod (reversedIntVal(d, base)) > 0) then return false |
|||
end repeat |
|||
return true |
|||
end hasSpecialDivisors |
|||
local output, base, n |
|||
set output to {} |
|||
set base to 10 |
|||
repeat with n from 1 to 199 |
|||
if (hasSpecialDivisors(n, base)) then set end of output to n |
|||
end repeat |
|||
return {|count|:(count output), finds:output}</lang> |
|||
{{output}} |
|||
<lang applescript>{|count|:72, finds:{1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 17, 19, 22, 23, 26, 27, 29, 31, 33, 37, 39, 41, 43, 44, 46, 47, 53, 55, 59, 61, 62, 66, 67, 69, 71, 73, 77, 79, 82, 83, 86, 88, 89, 93, 97, 99, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199}}</lang> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |