Numbers whose count of divisors is prime: Difference between revisions

Content added Content deleted
m (→‎{{header|AppleScript}}: Changed a couple of variable labels.)
m (→‎{{header|AppleScript}}: Variable label changed. Source of squares-only idea acknowledged.)
Line 163: Line 163:


=={{header|AppleScript}}==
=={{header|AppleScript}}==
Only squares checked, as per the Discussion page.
<syntaxhighlight lang="applescript">on countFactors(n) -- Positive ns only.
<syntaxhighlight lang="applescript">on countFactors(n) -- Positive ns only.
if (n < 4) then return 2 - ((n = 1) as integer)
if (n < 4) then return 2 - ((n = 1) as integer)
Line 189: Line 190:
on task()
on task()
set limit to 100000 - 1
set limit to 100000 - 1
set maxLen to (count (limit as text))
set nWidth to (count (limit as text))
set inset to " "'s text 1 thru (maxLen - 1)
set inset to " "'s text 1 thru (nWidth - 1)
set output to {"Positive integers < " & (limit + 1) & " whose divisor count is an odd prime:"}
set output to {"Positive integers < " & (limit + 1) & " whose divisor count is an odd prime:"}
set row to {}
set row to {}
Line 198: Line 199:
if (countFactors(countFactors(n)) = 2) then
if (countFactors(countFactors(n)) = 2) then
set counter to counter + 1
set counter to counter + 1
set row's end to (inset & n)'s text -maxLen thru -1
set row's end to (inset & n)'s text -nWidth thru -1
if ((count row) = 10) then
if ((count row) = 10) then
set output's end to join(row, " ")
set output's end to join(row, " ")