Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Circular-primes/Sidef/circular-primes.sidef
Normal file
29
Task/Circular-primes/Sidef/circular-primes.sidef
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
func is_circular_prime(n) {
|
||||
n.is_prime || return false
|
||||
|
||||
var circular = n.digits
|
||||
circular.min < circular.tail && return false
|
||||
|
||||
for k in (1 ..^ circular.len) {
|
||||
with (circular.rotate(k).digits2num) {|p|
|
||||
(p.is_prime && (p >= n)) || return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
say "The first 19 circular primes are:"
|
||||
say 19.by(is_circular_prime)
|
||||
|
||||
say "\nThe next 4 circular primes, in repunit format, are:"
|
||||
{|n| (10**n - 1)/9 -> is_prob_prime }.first(4, 4..Inf).each {|n|
|
||||
say "R(#{n})"
|
||||
}
|
||||
|
||||
say "\nRepunit testing:"
|
||||
[5003, 9887, 15073, 25031, 35317, 49081].each {|n|
|
||||
var now = Time.micro
|
||||
say ("R(#{n}) -> ", is_prob_prime((10**n - 1)/9) ? 'probably prime' : 'composite',
|
||||
" (took: #{'%.3f' % Time.micro-now} sec)")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue