Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
128
Task/Sphenic-numbers/AppleScript/sphenic-numbers-1.applescript
Normal file
128
Task/Sphenic-numbers/AppleScript/sphenic-numbers-1.applescript
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
on sieveOfEratosthenes(limit)
|
||||
set mv to missing value
|
||||
if (limit < 2) then return {}
|
||||
script o
|
||||
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
|
||||
if (limit > 2) then 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
|
||||
tell (n + 2) to if (it ≤ limit) then set o's numberList's item it to it
|
||||
end repeat
|
||||
-- "Cross out" slots for multiples of written-in numbers not then crossed out themselves.
|
||||
repeat with n from 5 to ((limit ^ 0.5) div 1) by 6
|
||||
repeat 2 times
|
||||
if (o's numberList's item n = n) then
|
||||
repeat with multiple from (n * n) to limit by n
|
||||
set item multiple of o's numberList to mv
|
||||
end repeat
|
||||
end if
|
||||
set n to n + 2
|
||||
end repeat
|
||||
end repeat
|
||||
return o's numberList's numbers
|
||||
end sieveOfEratosthenes
|
||||
|
||||
on prefabList(|size|, filler)
|
||||
if (|size| < 1) then return {}
|
||||
script o
|
||||
property lst : {filler}
|
||||
end script
|
||||
|
||||
set |count| to 1
|
||||
repeat until (|count| + |count| > |size|)
|
||||
set o's lst to o's lst & o's lst
|
||||
set |count| to |count| + |count|
|
||||
end repeat
|
||||
if (|count| < |size|) then set o's lst to o's lst & o's lst's items 1 thru (|size| - |count|)
|
||||
return o's lst
|
||||
end prefabList
|
||||
|
||||
on getSphenicsBelow(limit)
|
||||
set limit to limit - 1
|
||||
script o
|
||||
property primes : sieveOfEratosthenes(limit div (2 * 3))
|
||||
property sphenics : prefabList(limit, missing value)
|
||||
end script
|
||||
|
||||
repeat with a from 3 to (count o's primes)
|
||||
set x to o's primes's item a
|
||||
repeat with b from 2 to (a - 1)
|
||||
set y to x * (o's primes's item b)
|
||||
if (y ≥ limit) then exit repeat
|
||||
repeat with c from 1 to (b - 1)
|
||||
set z to y * (o's primes's item c)
|
||||
if (z > limit) then exit repeat
|
||||
set o's sphenics's item z to z
|
||||
end repeat
|
||||
end repeat
|
||||
end repeat
|
||||
return (o's sphenics's numbers)
|
||||
end getSphenicsBelow
|
||||
|
||||
on join(lst, delim)
|
||||
set astid to AppleScript's text item delimiters
|
||||
set AppleScript's text item delimiters to delim
|
||||
set txt to lst as text
|
||||
set AppleScript's text item delimiters to astid
|
||||
return txt
|
||||
end join
|
||||
|
||||
on primeFactors(n)
|
||||
set output to {}
|
||||
if (n < 2) then return output
|
||||
set limit to (n ^ 0.5) div 1
|
||||
set f to 2
|
||||
repeat until (f > limit)
|
||||
if (n mod f = 0) then
|
||||
set end of output to f
|
||||
set n to n div f
|
||||
repeat while (n mod f = 0)
|
||||
set n to n div f
|
||||
end repeat
|
||||
if (limit > n) then set limit to n
|
||||
end if
|
||||
set f to f + 1
|
||||
end repeat
|
||||
if (limit < n) then set end of output to n
|
||||
return output
|
||||
end primeFactors
|
||||
|
||||
on task()
|
||||
script o
|
||||
property sphenics : getSphenicsBelow(1000000)
|
||||
end script
|
||||
set {t1, t2, t3, t4, t5} to {{}, {}, count o's sphenics, 0, o's sphenics's 200000th item}
|
||||
repeat with i from 1 to (t3 - 2)
|
||||
set s to o's sphenics's item i
|
||||
if (s < 1000) then set end of t1 to text -4 thru -1 of (" " & s)
|
||||
set s2 to o's sphenics's item (i + 2)
|
||||
if (s2 - s = 2) then
|
||||
if (s2 < 10000) then ¬
|
||||
set end of t2 to "{" & join(o's sphenics's items i thru (i + 2), ", ") & "}"
|
||||
set t4 to t4 + 1
|
||||
if (t4 = 5000) then ¬
|
||||
set t6 to "{" & join(o's sphenics's items i thru (i + 2), ", ") & "}"
|
||||
end if
|
||||
end repeat
|
||||
|
||||
set output to {"Sphenic numbers < 1,000:"}
|
||||
repeat with i from 1 to 135 by 15
|
||||
set end of output to join(t1's items i thru (i + 14), "")
|
||||
end repeat
|
||||
set end of output to linefeed & "Sphenic triplets < 10,000:"
|
||||
repeat with i from 1 to 21 by 3
|
||||
set end of output to join(t2's items i thru (i + 2), " ")
|
||||
end repeat
|
||||
set end of output to linefeed & "There are " & t3 & " sphenic numbers < 1,000,000"
|
||||
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()
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
"Sphenic numbers < 1,000:
|
||||
30 42 66 70 78 102 105 110 114 130 138 154 165 170 174
|
||||
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285
|
||||
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406
|
||||
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494
|
||||
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609
|
||||
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678
|
||||
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795
|
||||
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902
|
||||
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994
|
||||
|
||||
Sphenic triplets < 10,000:
|
||||
{1309, 1310, 1311} {1885, 1886, 1887} {2013, 2014, 2015}
|
||||
{2665, 2666, 2667} {3729, 3730, 3731} {5133, 5134, 5135}
|
||||
{6061, 6062, 6063} {6213, 6214, 6215} {6305, 6306, 6307}
|
||||
{6477, 6478, 6479} {6853, 6854, 6855} {6985, 6986, 6987}
|
||||
{7257, 7258, 7259} {7953, 7954, 7955} {8393, 8394, 8395}
|
||||
{8533, 8534, 8535} {8785, 8786, 8787} {9213, 9214, 9215}
|
||||
{9453, 9454, 9455} {9821, 9822, 9823} {9877, 9878, 9879}
|
||||
|
||||
There are 206964 sphenic numbers < 1,000,000
|
||||
There are 5457 sphenic triplets < 1,000,000
|
||||
The 200,000th sphenic number is 966467 (17 * 139 * 409)
|
||||
The 5,000th sphenic triplet is {918005, 918006, 918007}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue