Sphenic numbers: Difference between revisions
m
→{{header|AppleScript}}: Minor tidying.
(→{{header|Phix}}: prepend Freepascal) |
m (→{{header|AppleScript}}: Minor tidying.) |
||
Line 54:
property numberList : prefabList(limit, mv)
end script
-- Write in 2, 3, and numbers which aren't their multiples.
set o's numberList's second item to 2
set o's numberList's third item to 3
repeat with n from 5 to limit by 6
set o's numberList's item n to n
Line 65 ⟶ 64:
set o's numberList's item n to mv
end repeat
-- "Cross out" slots for multiples of written-in numbers not then crossed out themselves.
repeat with n from
if (o's
end if▼
set item multiple of o's numberList to mv
end repeat
end if
end repeat
return o's numberList's numbers
end sieveOfEratosthenes
Line 89 ⟶ 84:
end script
set
repeat until (
set o's lst to o's lst & o's lst
set
end repeat
if (
return o's lst
end prefabList
Line 101 ⟶ 96:
set limit to limit - 1
script o
property primes : sieveOfEratosthenes(limit div
property sphenics : prefabList(limit, missing value)
end script
set i to 0
repeat with a from 3 to (count o's primes)
Line 133 ⟶ 129:
on primeFactors(n)
set output to {}
if (n < 2) then return output
set limit to (n ^ 0.5) div 1
set
repeat until (
if (n mod
set n to n div f
end repeat
▲ set end of output to i
if (limit > n) then set limit to n
end if
set
end repeat
if (limit < n) then set end of output to n
Line 153 ⟶ 151:
property sphenics : getSphenicsBelow(1000000)
end script
set {t1, t2, t3, t4, t5} to {{}, {}, count o's sphenics, 0, o's sphenics's
repeat with i from 1 to (
set s to o's sphenics's item i
if (s < 1000) then set end of t1 to text -4 thru -1 of (" " & s)
Line 160 ⟶ 158:
if (s2 - s = 2) then
if (s2 < 10000) then ¬
set end of t2 to "{" & join(
set t4 to t4 + 1
if (t4 = 5000) then ¬
set t6 to "{" & join(
end if
end repeat
Line 178 ⟶ 176:
set end of output to "There are " & t4 & " sphenic triplets < 1,000,000"
set end of output to "The 200,000th sphenic number is " & t5 & ¬
(" (" & join(primeFactors(t5), " * ") & ")")
set end of output to "The 5,000th sphenic triplet is " & t6
return join(output, linefeed)
end task
task()</syntaxhighlight>
{{output}}
|