Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
|
|
@ -1,7 +1,7 @@
|
|||
val .isPrime = f .i == 2 or .i > 2 and
|
||||
not any f(.x) .i div .x, pseries 2 .. .i ^/ 2
|
||||
val .isPrime = fn(.i) .i == 2 or .i > 2 and
|
||||
not any fn(.x) .i div .x, pseries 2 .. .i ^/ 2
|
||||
|
||||
val .sumDigits = f fold f{+}, s2n toString .i
|
||||
val .sumDigits = fn(.i) fold fn{+}, s2n string .i
|
||||
|
||||
writeln "Additive primes less than 500:"
|
||||
|
||||
|
|
@ -9,10 +9,10 @@ var .count = 0
|
|||
|
||||
for .i in [2] ~ series(3..500, 2) {
|
||||
if .isPrime(.i) and .isPrime(.sumDigits(.i)) {
|
||||
write $"\.i:3; "
|
||||
write $"\{.i:3} "
|
||||
.count += 1
|
||||
if .count div 10: writeln()
|
||||
}
|
||||
}
|
||||
|
||||
writeln $"\n\n\.count; additive primes found.\n"
|
||||
writeln $"\n\n\{.count} additive primes found.\n"
|
||||
|
|
|
|||
21
Task/Additive-primes/Miranda/additive-primes.miranda
Normal file
21
Task/Additive-primes/Miranda/additive-primes.miranda
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
main :: [sys_message]
|
||||
main = [Stdout (table 5 10 nums), Stdout countmsg]
|
||||
where nums = filter additive_prime [1..500]
|
||||
countmsg = "Found " ++ show (#nums) ++ " additive primes < 500\n"
|
||||
|
||||
table :: num->num->[num]->[char]
|
||||
table w c ls = lay [concat (map (rjustify w . show) l) | l <- split c ls]
|
||||
|
||||
split :: num->[*]->[[*]]
|
||||
split n ls = [ls], if #ls < n
|
||||
= take n ls:split n (drop n ls), otherwise
|
||||
|
||||
additive_prime :: num->bool
|
||||
additive_prime n = prime (dsum n) & prime n
|
||||
|
||||
dsum :: num->num
|
||||
dsum n = n, if n<10
|
||||
= n mod 10 + dsum (n div 10), otherwise
|
||||
|
||||
prime :: num->bool
|
||||
prime n = n>=2 & #[d | d<-[2..entier (sqrt n)]; n mod d=0] = 0
|
||||
|
|
@ -1,44 +1,65 @@
|
|||
/*REXX program counts/displays the number of additive primes under a specified number N.*/
|
||||
parse arg n cols . /*get optional number of primes to find*/
|
||||
if n=='' | n=="," then n= 500 /*Not specified? Then assume default.*/
|
||||
if cols=='' | cols=="," then cols= 10 /* " " " " " */
|
||||
call genP n /*generate all primes under N. */
|
||||
w= 10 /*width of a number in any column. */
|
||||
title= " additive primes that are < " commas(n)
|
||||
if cols>0 then say ' index │'center(title, 1 + cols*(w+1) )
|
||||
if cols>0 then say '───────┼'center("" , 1 + cols*(w+1), '─')
|
||||
found= 0; idx= 1 /*initialize # of additive primes & IDX*/
|
||||
$= /*a list of additive primes (so far). */
|
||||
do j=1 for #; p= @.j /*obtain the Jth prime. */
|
||||
_= sumDigs(p); if \!._ then iterate /*is sum of J's digs a prime? No, skip.*/ /* ◄■■■■■■■■ a filter. */
|
||||
found= found + 1 /*bump the count of additive primes. */
|
||||
if cols<0 then iterate /*Build the list (to be shown later)? */
|
||||
c= commas(p) /*maybe add commas to the number. */
|
||||
$= $ right(c, max(w, length(c) ) ) /*add additive prime──►list, allow big#*/
|
||||
if found//cols\==0 then iterate /*have we populated a line of output? */
|
||||
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
|
||||
idx= idx + cols /*bump the index count for the output*/
|
||||
end /*j*/
|
||||
/*REXX program counts/displays the number of additive primes less than N. */
|
||||
Parse Arg n cols . /*get optional number of primes To find*/
|
||||
If n=='' | n==',' Then n= 500 /*Not specified? Then assume default.*/
|
||||
If cols=='' | cols==',' Then cols= 10 /* ' ' ' ' ' */
|
||||
call genP n /*generate all primes under N. */
|
||||
w=5 /*width of a number in any column. */
|
||||
title= 'additive primes that are < 'commas(n)
|
||||
If cols>0 Then Say ' index ¦'center(title,cols*(w+1)+1)
|
||||
If cols>0 Then Say '-------+'center('' ,cols*(w+1)+1,'-')
|
||||
found=0
|
||||
ol='' /*a list of additive primes (so far). */
|
||||
idx=1
|
||||
Do j=1 By 1
|
||||
p=p.j /*obtain the Jth prime. */
|
||||
If p>n Then Leave /* no more needed */
|
||||
_=sumDigs(p)
|
||||
If !._ Then Do
|
||||
found=found+1 /*bump the count of additive primes. */
|
||||
c=commas(p) /*maybe add commas To the number. */
|
||||
ol=ol right(c,max(w,length(c))) /*add additive prime--?list,allow big# */
|
||||
If words(ol)=10 Then Do /* a line is complete */
|
||||
Say center(idx,7)'¦' substr(ol,2) /*display what we have so far (cols). */
|
||||
ol='' /* prepare for next line */
|
||||
idx=idx+10
|
||||
End
|
||||
End
|
||||
End /*j*/
|
||||
|
||||
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
|
||||
if cols>0 then say '───────┴'center("" , 1 + cols*(w+1), '─')
|
||||
say
|
||||
say 'found ' commas(found) title
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
|
||||
sumDigs: parse arg x 1 s 2; do k=2 for length(x)-1; s= s + substr(x,k,1); end; return s
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
genP: parse arg n; @.1= 2; @.2= 3; @.3= 5; @.4= 7; @.5= 11; @.6= 13
|
||||
!.= 0; !.2= 1; !.3= 1; !.5= 1; !.7= 1; !.11= 1; !.13= 1
|
||||
#= 6; sq.#= @.# ** 2 /*the number of primes; prime squared.*/
|
||||
do j=@.#+2 by 2 for max(0, n%2-@.#%2-1) /*find odd primes from here on. */
|
||||
parse var j '' -1 _ /*obtain the last digit of the J var.*/
|
||||
if _==5 then iterate; if j// 3==0 then iterate /*J ÷ by 5? J ÷ by 3? */
|
||||
if j// 7==0 then iterate; if j//11==0 then iterate /*" " " 7? " " " 11? */
|
||||
/* [↓] divide by the primes. ___ */
|
||||
do k=6 while sq.k<=j /*divide J by other primes ≤ √ J */
|
||||
if j//@.k==0 then iterate j /*÷ by prev. prime? ¬prime ___ */
|
||||
end /*k*/ /* [↑] only divide up to √ J */
|
||||
#= # + 1; @.#= j; sq.#= j*j; !.j= 1 /*bump prime count; assign prime & flag*/
|
||||
end /*j*/; return
|
||||
If ol\=='' Then
|
||||
Say center(idx,7)'¦' substr(ol,2) /*possible display residual output. */
|
||||
If cols>0 Then
|
||||
Say '--------'center('',cols*(w+1)+1,'-')
|
||||
Say
|
||||
Say 'found ' commas(found) title
|
||||
Exit 0 /*stick a fork in it, we're all done. */
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
commas: Parse Arg ?; Do jc=length(?)-3 To 1 by -3; ?=insert(',',?,jc); End; Return ?
|
||||
sumDigs:Parse Arg x 1 s 2; Do k=2 For length(x)-1; s=s+substr(x,k,1); End; Return s
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
genP:
|
||||
Parse Arg n
|
||||
pl=2 3 5 7 11 13
|
||||
!.=0
|
||||
Do np=1 By 1 While pl<>''
|
||||
Parse Var pl p pl
|
||||
p.np=p
|
||||
sq.np=p*p
|
||||
!.p=1
|
||||
End
|
||||
np=np-1
|
||||
Do j=p.np+2 by 2 While j<n
|
||||
Parse Var j '' -1 _ /*obtain the last digit of the J var.*/
|
||||
If _==5 Then Iterate
|
||||
If j// 3==0 Then Iterate
|
||||
If j// 7==0 Then Iterate
|
||||
If j//11==0 Then Iterate
|
||||
Do k=6 By 1 While sq.k<=j /*divide J by other primes <=sqrt(j) */
|
||||
If j//p.k==0 Then Iterate j /* not prime - try next */
|
||||
End /*k*/
|
||||
np=np+1 /*bump prime count; assign prime & flag*/
|
||||
p.np=j
|
||||
sq.np=j*j
|
||||
!.j=1
|
||||
End /*j*/
|
||||
Return
|
||||
|
|
|
|||
26
Task/Additive-primes/SETL/additive-primes.setl
Normal file
26
Task/Additive-primes/SETL/additive-primes.setl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
program additive_primes;
|
||||
loop for i in [i : i in [1..499] | additive_prime i] do
|
||||
nprint(lpad(str i, 4));
|
||||
if (n +:= 1) mod 10 = 0 then
|
||||
print;
|
||||
end if;
|
||||
end loop;
|
||||
print;
|
||||
print("There are " + str n + " additive primes less than 500.");
|
||||
|
||||
op additive_prime(n);
|
||||
return prime n and prime digitsum n;
|
||||
end op;
|
||||
|
||||
op prime(n);
|
||||
return n>=2 and not exists d in {2..floor sqrt n} | n mod d = 0;
|
||||
end op;
|
||||
|
||||
op digitsum(n);
|
||||
loop while n>0;
|
||||
s +:= n mod 10;
|
||||
n div:= 10;
|
||||
end loop;
|
||||
return s;
|
||||
end op;
|
||||
end program;
|
||||
15
Task/Additive-primes/Uiua/additive-primes.uiua
Normal file
15
Task/Additive-primes/Uiua/additive-primes.uiua
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[] # list of primes to be populated
|
||||
↘2⇡500 # candidates (starting at 2)
|
||||
|
||||
# Take the first remaining candidate, which will be prime, save it,
|
||||
# then remove every candidate that it divides. Repeat until none left.
|
||||
⍢(▽≠0◿⊃⊢(.↘1)⟜(⊂⊢)|>0⧻)
|
||||
# Tidy up.
|
||||
⇌◌
|
||||
|
||||
# Build sum of digits of each.
|
||||
≡(/+≡⋕°⋕)...
|
||||
# Mask out those that result in non-primes.
|
||||
⊏⊚±⬚0⊏⊗
|
||||
# Return values and length.
|
||||
⧻.
|
||||
Loading…
Add table
Add a link
Reference in a new issue