Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
121
Task/Cyclops-numbers/AppleScript/cyclops-numbers-1.applescript
Normal file
121
Task/Cyclops-numbers/AppleScript/cyclops-numbers-1.applescript
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
on task()
|
||||
script o
|
||||
property cyclopses : {}
|
||||
property primeCyclopses : {}
|
||||
property blindPrimeCyclopses : {}
|
||||
property palindromicPrimeCyclopses : {}
|
||||
|
||||
on add1(digitList)
|
||||
set carry to 1
|
||||
repeat with i from (count digitList) to 1 by -1
|
||||
set columnSum to (digitList's item i) + carry
|
||||
if (columnSum < 10) then
|
||||
set digitList's item i to columnSum
|
||||
return false -- Finish and indicate "no carry".
|
||||
end if
|
||||
-- Otherwise set this digit to 1 instead of to 0 and "carry" on. ;)
|
||||
set digitList's item i to 1
|
||||
end repeat
|
||||
return true
|
||||
end add1
|
||||
|
||||
on intFromDigits(digitList)
|
||||
if (digitList = {}) then return 0
|
||||
set n to digitList's beginning
|
||||
repeat with i from 2 to (count digitList)
|
||||
set n to n * 10 + (digitList's item i)
|
||||
end repeat
|
||||
return n
|
||||
end intFromDigits
|
||||
|
||||
on store(cyclops, lst, counter)
|
||||
if (counter < 51) then
|
||||
set lst's end to cyclops
|
||||
else if (cyclops > 10000000) then
|
||||
set lst's end to {cyclops, counter}
|
||||
return false -- No more for this list, thanks.
|
||||
end if
|
||||
return true
|
||||
end store
|
||||
end script
|
||||
|
||||
set {leftDigits, rightDigits, rightless, shiftFactor} to {{}, {}, 0, 10}
|
||||
set {cRef, pcRef, bpcRef, ppcRef} to {a reference to o's cyclopses, ¬
|
||||
a reference to o's primeCyclopses, a reference to o's blindPrimeCyclopses, ¬
|
||||
a reference to o's palindromicPrimeCyclopses}
|
||||
set {cCount, pcCount, bpcCount, ppcCount} to {0, 0, 0, 0}
|
||||
set {cActive, pcActive, bpcActive, ppcActive} to {true, true, true, true}
|
||||
repeat while ((bpcActive) or (ppcActive))
|
||||
set |right| to o's intFromDigits(rightDigits)
|
||||
set cyclops to rightless + |right|
|
||||
if (cActive) then
|
||||
set cCount to cCount + 1
|
||||
set cActive to o's store(cyclops, cRef, cCount)
|
||||
end if
|
||||
if (isPrime(cyclops)) then
|
||||
if (pcActive) then
|
||||
set pcCount to pcCount + 1
|
||||
set pcActive to o's store(cyclops, pcRef, pcCount)
|
||||
end if
|
||||
if (bpcActive) then
|
||||
set blinded to rightless div 10 + |right|
|
||||
if (isPrime(blinded)) then
|
||||
set bpcCount to bpcCount + 1
|
||||
set bpcActive to o's store(cyclops, bpcRef, bpcCount)
|
||||
end if
|
||||
end if
|
||||
if ((ppcActive) and (rightDigits = stigiDtfel)) then
|
||||
set ppcCount to ppcCount + 1
|
||||
set ppcActive to o's store(cyclops, ppcRef, ppcCount)
|
||||
end if
|
||||
end if
|
||||
if (o's add1(rightDigits)) then
|
||||
-- Adding 1 to rightDigits produced a carry. Add 1 to leftDigits too.
|
||||
if (o's add1(leftDigits)) then
|
||||
-- Also carried. Extend both lists by 1 digit.
|
||||
set {leftDigits's beginning, rightDigits's beginning} to {1, 1}
|
||||
set shiftFactor to shiftFactor * 10
|
||||
end if
|
||||
set rightless to (o's intFromDigits(leftDigits)) * shiftFactor
|
||||
set stigiDtfel to leftDigits's reverse
|
||||
end if
|
||||
end repeat
|
||||
|
||||
set output to {}
|
||||
repeat with this in {{"", o's cyclopses}, {"prime ", o's primeCyclopses}, ¬
|
||||
{"blind prime ", o's blindPrimeCyclopses}, ¬
|
||||
{"palindromic prime ", o's palindromicPrimeCyclopses}}
|
||||
set {type, cyclopses} to this
|
||||
set output's end to linefeed & "First 50 " & type & "cyclops numbers:"
|
||||
repeat with i from 1 to 50 by 10
|
||||
set row to {}
|
||||
repeat with j from i to (i + 9)
|
||||
set row's end to (" " & cyclopses's item j)'s text -7 thru -1
|
||||
end repeat
|
||||
set output's end to join(row, " ")
|
||||
end repeat
|
||||
set {nth, n} to cyclopses's end
|
||||
set output's end to "The first such number > ten million is the " & n & "th: " & nth
|
||||
end repeat
|
||||
join(output, linefeed)
|
||||
end task
|
||||
|
||||
on isPrime(n)
|
||||
if (n < 4) then return (n > 1)
|
||||
if ((n mod 2 is 0) or (n mod 3 is 0)) then return false
|
||||
repeat with i from 5 to (n ^ 0.5) div 1 by 6
|
||||
if ((n mod i is 0) or (n mod (i + 2) is 0)) then return false
|
||||
end repeat
|
||||
|
||||
return true
|
||||
end isPrime
|
||||
|
||||
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
|
||||
|
||||
task()
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
"
|
||||
First 50 cyclops numbers:
|
||||
0 101 102 103 104 105 106 107 108 109
|
||||
201 202 203 204 205 206 207 208 209 301
|
||||
302 303 304 305 306 307 308 309 401 402
|
||||
403 404 405 406 407 408 409 501 502 503
|
||||
504 505 506 507 508 509 601 602 603 604
|
||||
The first such number > ten million is the 538085th: 111101111
|
||||
|
||||
First 50 prime cyclops numbers:
|
||||
101 103 107 109 307 401 409 503 509 601
|
||||
607 701 709 809 907 11027 11047 11057 11059 11069
|
||||
11071 11083 11087 11093 12011 12037 12041 12043 12049 12071
|
||||
12073 12097 13033 13037 13043 13049 13063 13093 13099 14011
|
||||
14029 14033 14051 14057 14071 14081 14083 14087 15013 15017
|
||||
The first such number > ten million is the 39320th: 111101129
|
||||
|
||||
First 50 blind prime cyclops numbers:
|
||||
101 103 107 109 307 401 503 509 601 607
|
||||
701 709 809 907 11071 11087 11093 12037 12049 12097
|
||||
13099 14029 14033 14051 14071 14081 14083 14087 15031 15053
|
||||
15083 16057 16063 16067 16069 16097 17021 17033 17041 17047
|
||||
17053 17077 18047 18061 18077 18089 19013 19031 19051 19073
|
||||
The first such number > ten million is the 11394th: 111101161
|
||||
|
||||
First 50 palindromic prime cyclops numbers:
|
||||
101 16061 31013 35053 38083 73037 74047 91019 94049 1120211
|
||||
1150511 1160611 1180811 1190911 1250521 1280821 1360631 1390931 1490941 1520251
|
||||
1550551 1580851 1630361 1640461 1660661 1670761 1730371 1820281 1880881 1930391
|
||||
1970791 3140413 3160613 3260623 3310133 3380833 3460643 3470743 3590953 3670763
|
||||
3680863 3970793 7190917 7250527 7310137 7540457 7630367 7690967 7750577 7820287
|
||||
The first such number > ten million is the 67th: 114808411"
|
||||
Loading…
Add table
Add a link
Reference in a new issue