Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
7
Task/Semiprime/Bracmat/semiprime-1.bracmat
Normal file
7
Task/Semiprime/Bracmat/semiprime-1.bracmat
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
semiprime=
|
||||
m n a b
|
||||
. 2^-64:?m
|
||||
& 2*!m:?n
|
||||
& !arg^!m
|
||||
: (#%?a^!m*#%?b^!m|#%?a^!n&!a:?b)
|
||||
& (!a.!b);
|
||||
7
Task/Semiprime/Bracmat/semiprime-2.bracmat
Normal file
7
Task/Semiprime/Bracmat/semiprime-2.bracmat
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
2^63:?u
|
||||
& whl
|
||||
' ( -1+!u:>2:?u
|
||||
& ( semiprime$!u:?R&out$(!u ":" !R)
|
||||
|
|
||||
)
|
||||
);
|
||||
48
Task/Semiprime/DCL/semiprime.dcl
Normal file
48
Task/Semiprime/DCL/semiprime.dcl
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
$ p1 = f$integer( p1 )
|
||||
$ if p1 .lt. 2
|
||||
$ then
|
||||
$ write sys$output "out of range 2 thru 2^31-1"
|
||||
$ exit
|
||||
$ endif
|
||||
$
|
||||
$ close /nolog primes
|
||||
$ on control_y then $ goto clean
|
||||
$ open primes primes.txt
|
||||
$
|
||||
$ loop1:
|
||||
$ read /end_of_file = prime primes prime
|
||||
$ prime = f$integer( prime )
|
||||
$ loop2:
|
||||
$ t = p1 / prime
|
||||
$ if t * prime .eq. p1
|
||||
$ then
|
||||
$ if f$type( factorization ) .eqs. ""
|
||||
$ then
|
||||
$ factorization = f$string( prime )
|
||||
$ else
|
||||
$ factorization = factorization + "*" + f$string( prime )
|
||||
$ endif
|
||||
$ if t .eq. 1 then $ goto done
|
||||
$ p1 = t
|
||||
$ goto loop2
|
||||
$ else
|
||||
$ goto loop1
|
||||
$ endif
|
||||
$ prime:
|
||||
$ if f$type( factorization ) .eqs. ""
|
||||
$ then
|
||||
$ factorization = f$string( p1 )
|
||||
$ else
|
||||
$ factorization = factorization + "*" + f$string( p1 )
|
||||
$ endif
|
||||
$ done:
|
||||
$ show symbol factorization
|
||||
$ if f$locate( "*", factorization ) .eq. f$length( factorization )
|
||||
$ then
|
||||
$ write sys$output "so, it is prime"
|
||||
$ else
|
||||
$ if f$element( 2, "*", factorization ) .eqs. "*" then $ write sys$output "so, it is semiprime"
|
||||
$ endif
|
||||
$
|
||||
$ clean:
|
||||
$ close primes
|
||||
19
Task/Semiprime/Erlang/semiprime.erl
Normal file
19
Task/Semiprime/Erlang/semiprime.erl
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
-module(factors).
|
||||
-export([factors/1,kthfactor/2]).
|
||||
|
||||
factors(N) ->
|
||||
factors(N,2,[]).
|
||||
|
||||
factors(1,_,Acc) -> Acc;
|
||||
factors(N,K,Acc) when N rem K == 0 ->
|
||||
factors(N div K,K, [K|Acc]);
|
||||
factors(N,K,Acc) ->
|
||||
factors(N,K+1,Acc).
|
||||
|
||||
|
||||
% is integer N factorable into M primes?
|
||||
kthfactor(N,M) ->
|
||||
case length(factors(N)) of M ->
|
||||
factors(N);
|
||||
_ ->
|
||||
false end.
|
||||
10
Task/Semiprime/Maple/semiprime-1.maple
Normal file
10
Task/Semiprime/Maple/semiprime-1.maple
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
SemiPrimes := proc( n )
|
||||
local fact;
|
||||
fact := numtheory:-divisors( n ) minus {1, n};
|
||||
if numelems( fact ) in {1,2} and not( member( 'false', isprime ~ ( fact ) ) ) then
|
||||
return n;
|
||||
else
|
||||
return NULL;
|
||||
end if;
|
||||
end proc:
|
||||
{ seq( SemiPrime( i ), i = 1..100 ) };
|
||||
1
Task/Semiprime/Maple/semiprime-2.maple
Normal file
1
Task/Semiprime/Maple/semiprime-2.maple
Normal file
|
|
@ -0,0 +1 @@
|
|||
{ 4,6,9,10,14,15,21,22,25,26,33,34,35,38,39,46,49,51,55,57,58,62,65,69,74,77,82,85,86,87,91,93,94,95 }
|
||||
|
|
@ -1,30 +1,31 @@
|
|||
/*REXX program determines if any number (or a range) is/are semiprime.*/
|
||||
parse arg bot top . /*obtain #s from the command line*/
|
||||
if bot=='' then bot=random() /*so, the user wants us to guess.*/
|
||||
if top=='' then top=bot /*maybe define a range of numbers*/
|
||||
w=max(length(bot), length(top)) /*get maximum width of numbers. */
|
||||
if w>digits() then numeric digits w /*is there enough digits ? */
|
||||
do n=bot to top /*show results for a range of #s.*/
|
||||
if isSemiPrime(n) then say right(n,w) ' is semiprime.'
|
||||
else say right(n,w) " isn't semiprime."
|
||||
/*REXX program determines if any number (or a range) is/are semiprime. */
|
||||
parse arg bot top . /*obtain optional numbers from the C.L.*/
|
||||
if bot==''|bot=="," then bot=random() /*None given? User wants us to guess.*/
|
||||
if top==''|top=="," then top=bot /*maybe define a range of numbers. */
|
||||
w=max(length(bot), length(top)) /*obtain the maximum width of numbers. */
|
||||
numeric digits max(9,w) /*ensure there're enough decimal digits*/
|
||||
do n=bot to top /*show results for a range of numbers. */
|
||||
if isSemiPrime(n) then say right(n,w) " is semiprime."
|
||||
else say right(n,w) " isn't semiprime."
|
||||
end /*n*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────ISPRIME subroutine──────────────────*/
|
||||
isPrime: procedure; parse arg x; if x<2 then return 0
|
||||
if wordpos(x,'2 3 5 7')\==0 then return 1 /*handle some special cases*/
|
||||
do i=2 for 2; if x//i==0 then return 0; end /*i*/ /*÷ by 2 & 3*/
|
||||
do j=5 by 6 until j*j>x; if x//j==0 then return 0 /*¬ a prime#*/
|
||||
if x//(j+2)==0 then return 0 /*¬ a prime#*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
isPrime: procedure; parse arg x; if x<2 then return 0 /*number too low*/
|
||||
if wordpos(x, '2 3 5 7 11 13 17 19 23')\==0 then return 1 /*it's low prime*/
|
||||
if x//2==0 then return 0; if x//3==0 then return 0 /*÷ by 2;÷ by 3?*/
|
||||
do j=5 by 6 until j*j>x; if x//j==0 then return 0 /*not a prime. */
|
||||
if x//(j+2)==0 then return 0 /* " " " */
|
||||
end /*j*/
|
||||
return 1 /*X is a prime number, for sure.*/
|
||||
/*──────────────────────────────────ISSEMIPRIME subroutine──────────────*/
|
||||
isSemiPrime: procedure; arg x; if \datatype(x,'W') | x<4 then return 0
|
||||
x=x/1 /*normalize the X number. */
|
||||
do i=2 for 2; if x//i==0 then if isPrime(x%i) then return 1
|
||||
else return 0
|
||||
end /*i*/ /* [↑] divides by two and three.*/
|
||||
do j=5 by 6; if j*j>x then return 0 /*÷ by #s. */
|
||||
return 1 /*indicate that X is a prime number. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
isSemiPrime: procedure; parse arg x; if \datatype(x,'W') | x<4 then return 0
|
||||
x=x/1
|
||||
do i=2 for 2; if x//i==0 then if isPrime(x%i) then return 1
|
||||
else return 0
|
||||
end /*i*/
|
||||
/* ___ */
|
||||
do j=5 by 6; if j*j>x then return 0 /* > √ x ? */
|
||||
do k=j by 2 for 2; if x//k==0 then if isPrime(x%k) then return 1
|
||||
else return 0
|
||||
end /*k*/ /*see if 2nd factor is prime or ¬*/
|
||||
end /*j*/ /*[↑] never ÷ by # divisible by 3*/
|
||||
end /*k*/ /* [↑] see if 2nd factor is prime or ¬*/
|
||||
end /*j*/ /* [↑] never ÷ by J if J is mult. of 3*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue