Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -1,13 +1,8 @@
|
|||
fastfunc prime n .
|
||||
if n mod 2 = 0 and n > 2
|
||||
return 0
|
||||
.
|
||||
if n mod 2 = 0 and n > 2 : return 0
|
||||
i = 3
|
||||
sq = sqrt n
|
||||
while i <= sq
|
||||
if n mod i = 0
|
||||
return 0
|
||||
.
|
||||
while i <= sqrt n
|
||||
if n mod i = 0 : return 0
|
||||
i += 2
|
||||
.
|
||||
return 1
|
||||
|
|
@ -22,14 +17,10 @@ func cycle n .
|
|||
return m + n mod p * 10
|
||||
.
|
||||
func circprime p .
|
||||
if prime p = 0
|
||||
return 0
|
||||
.
|
||||
if prime p = 0 : return 0
|
||||
p2 = cycle p
|
||||
while p2 <> p
|
||||
if p2 < p or prime p2 = 0
|
||||
return 0
|
||||
.
|
||||
if p2 < p or prime p2 = 0 : return 0
|
||||
p2 = cycle p2
|
||||
.
|
||||
return 1
|
||||
|
|
@ -37,7 +28,7 @@ func circprime p .
|
|||
p = 2
|
||||
while count < 19
|
||||
if circprime p = 1
|
||||
print p
|
||||
write p & " "
|
||||
count += 1
|
||||
.
|
||||
p += 1
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
/*REXX program finds & displays circular primes (with a title & in a horizontal format).*/
|
||||
parse arg N hp . /*obtain optional arguments from the CL*/
|
||||
if N=='' | N=="," then N= 19 /* " " " " " " */
|
||||
if hp=='' | hp=="," then hip= 1000000 /* " " " " " " */
|
||||
call genP /*gen primes up to hp (200,000). */
|
||||
q= 024568 /*digs that most circular P can't have.*/
|
||||
found= 0; $= /*found: circular P count; $: a list.*/
|
||||
do j=1 until found==N; p= @.j /* [↓] traipse through all the primes.*/
|
||||
if p>9 & verify(p, q, 'M')>0 then iterate /*Does J contain forbidden digs? Skip.*/
|
||||
if \circP(p) then iterate /*Not circular? Then skip this number.*/
|
||||
found= found + 1 /*bump the count of circular primes. */
|
||||
$= $ p /*add this prime number ──► $ list. */
|
||||
end /*j*/ /*at this point, $ has a leading blank.*/
|
||||
|
||||
say center(' first ' found " circular primes ", 79, '─')
|
||||
say strip($)
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
circP: procedure expose @. !.; parse arg x 1 ox /*obtain a prime number to be examined.*/
|
||||
do length(x)-1; parse var x f 2 y /*parse X number, rotating the digits*/
|
||||
x= y || f /*construct a new possible circular P. */
|
||||
if x<ox then return 0 /*is number < the original? ¬ circular*/
|
||||
if \!.x then return 0 /* " " not prime? ¬ circular*/
|
||||
end /*length(x)···*/
|
||||
return 1 /*passed all tests, X is a circular P.*/
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
genP: @.1=2; @.2=3; @.3=5; @.4=7; @.5=11; @.6=13; @.7=17; @.8=19 /*assign Ps; #Ps*/
|
||||
!.= 0; !.2=1; !.3=1; !.5=1; !.7=1; !.11=1; !.13=1; !.17=1; !.19=1 /* " primality*/
|
||||
#= 8; sq.#= @.# **2 /*number of primes so far; prime square*/
|
||||
do j=@.#+4 by 2 to hip; parse var j '' -1 _ /*get last decimal digit of J. */
|
||||
if _==5 then iterate; if j// 3==0 then iterate; if j// 7==0 then iterate
|
||||
if j//11==0 then iterate; if j//13==0 then iterate; if j//17==0 then iterate
|
||||
do k=8 while sq.k<=j /*divide by some generated odd primes. */
|
||||
if j // @.k==0 then iterate j /*Is J divisible by P? Then not prime*/
|
||||
end /*k*/ /* [↓] a prime (J) has been found. */
|
||||
#= #+1; !.j= 1; sq.#= j*j; @.#= j /*bump P cnt; assign P to @. and !. */
|
||||
end /*j*/; return
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
-- 8 May 2025
|
||||
include Settings
|
||||
|
||||
say version; say 'Circular primes'; say
|
||||
say 'CIRCULAR PRIMES'
|
||||
say version
|
||||
say
|
||||
call First19
|
||||
call Next3
|
||||
call HigherReps
|
||||
|
|
@ -13,7 +16,7 @@ numeric digits 10
|
|||
say 'First 19 circular primes:'
|
||||
p = Primes(200000)
|
||||
do i = 1 to p
|
||||
a = prim.prime.i
|
||||
a = prim.i
|
||||
if Verify(a,'024568','m') > 0 then
|
||||
iterate i
|
||||
b = a; l = Length(b)
|
||||
|
|
@ -21,7 +24,7 @@ do i = 1 to p
|
|||
b = Right(b,l-1)||Left(b,1)
|
||||
if b < a then
|
||||
iterate i
|
||||
if \ prime(b) then
|
||||
if \ Prime(b) then
|
||||
iterate i
|
||||
end
|
||||
call Charout ,a' '
|
||||
|
|
@ -38,8 +41,8 @@ numeric digits 320
|
|||
say 'Next 3 circular primes:'
|
||||
do i = 7 to 320
|
||||
r = Repunit(i)
|
||||
if prime(r) then
|
||||
call charout ,'R('i') '
|
||||
if Prime(r) then
|
||||
call Charout ,'R('i') '
|
||||
end
|
||||
say
|
||||
say Format(Time('e'),,3) 'seconds'
|
||||
|
|
@ -51,7 +54,7 @@ procedure expose glob.
|
|||
call Time('r')
|
||||
numeric digits 1040
|
||||
say 'Primality of R(1031):'
|
||||
if prime(Repunit(1031)) then
|
||||
if Prime(Repunit(1031)) then
|
||||
say 'R(1031) is probable prime'
|
||||
else
|
||||
say 'R(1031) is composite'
|
||||
|
|
@ -59,14 +62,8 @@ say Format(Time('e'),,3) 'seconds'
|
|||
say
|
||||
return
|
||||
|
||||
Repunit:
|
||||
/* Repeat 1's function */
|
||||
procedure expose glob.
|
||||
arg x
|
||||
/* Formula */
|
||||
return Copies('1',x)
|
||||
|
||||
include Functions
|
||||
include Special
|
||||
include Numbers
|
||||
include Sequences
|
||||
include Abend
|
||||
82
Task/Circular-primes/Scheme/circular-primes.scm
Normal file
82
Task/Circular-primes/Scheme/circular-primes.scm
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
(import srfi-1)
|
||||
|
||||
; rotate list by n
|
||||
(define (rotate lst n)
|
||||
(if (> n 0)
|
||||
(append (drop lst n) (take lst n))
|
||||
(append (take-right lst (abs n)) (drop-right lst (abs n)))))
|
||||
|
||||
|
||||
; prime check
|
||||
(define (prime? n)
|
||||
(if (< n 4) (> n 1)
|
||||
(and (odd? n)
|
||||
(let loop ((k 3))
|
||||
(or (> (* k k) n)
|
||||
(and (positive? (remainder n k))
|
||||
(loop (+ k 2))))))))
|
||||
|
||||
; returns number rotated in lists
|
||||
(define (circ_lists lst)
|
||||
(let
|
||||
(
|
||||
(len (length lst))
|
||||
)
|
||||
(do (
|
||||
(remaining 1 (+ 1 remaining))
|
||||
(circs '() (cons (rotate lst remaining) circs ))
|
||||
)
|
||||
((< len remaining) circs)
|
||||
)
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
; helper function to make number a list to rotate it
|
||||
(define (number->list x)
|
||||
(string->list (number->string x))
|
||||
)
|
||||
|
||||
; returns list to number
|
||||
(define (list->number x)
|
||||
(string->number (list->string x))
|
||||
)
|
||||
|
||||
; checks if number is prime when the number is turned into lists
|
||||
(define (check x)
|
||||
(not (member #f (map prime? (map list->number (circ_lists (number->list x))))))
|
||||
)
|
||||
|
||||
; all permutations of a number
|
||||
(define (perms x)
|
||||
(map list->number (circ_lists (number->list x)))
|
||||
)
|
||||
|
||||
(define limit 19)
|
||||
|
||||
; checks if all permutations of x are not in lst
|
||||
(define (not_perm x lst)
|
||||
(equal? '() (filter-map (lambda (x) (not (equal? #f x)))
|
||||
(map (lambda (x) (member x lst)) (perms x))))
|
||||
)
|
||||
|
||||
|
||||
(define (circular_primes x lst)
|
||||
(cond
|
||||
(
|
||||
(< (length lst) limit)
|
||||
; if is true if all permutations are prime and if all permutations are not already in the lst, which is returned
|
||||
(if (and (equal? #t (check x)) (equal? #t (not_perm x lst)))
|
||||
(circular_primes (+ x 1) (cons x lst))
|
||||
(circular_primes (+ x 1) lst)
|
||||
)
|
||||
)
|
||||
(
|
||||
lst
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(display (reverse (circular_primes 2 '())))
|
||||
|
||||
(newline)
|
||||
Loading…
Add table
Add a link
Reference in a new issue