Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
26
Task/Semiprime/ERRE/semiprime.erre
Normal file
26
Task/Semiprime/ERRE/semiprime.erre
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
PROGRAM SEMIPRIME_NUMBER
|
||||
|
||||
!VAR I%
|
||||
|
||||
PROCEDURE SEMIPRIME(N%->RESULT%)
|
||||
LOCAL F%,P%
|
||||
P%=2
|
||||
LOOP
|
||||
EXIT IF NOT(F%<2 AND P%*P%<=N%)
|
||||
WHILE (N% MOD P%)=0 DO
|
||||
N%=N% DIV P%
|
||||
F%+=1
|
||||
END WHILE
|
||||
P%+=1
|
||||
END LOOP
|
||||
RESULT%=F%-(N%>1)=2
|
||||
END PROCEDURE
|
||||
|
||||
BEGIN
|
||||
PRINT(CHR$(12);) !CLS
|
||||
FOR I%=2 TO 100 DO
|
||||
SEMIPRIME(I%->RESULT%)
|
||||
IF RESULT% THEN PRINT(I%;) END IF
|
||||
END FOR
|
||||
PRINT
|
||||
END PROGRAM
|
||||
20
Task/Semiprime/EchoLisp/semiprime.echolisp
Normal file
20
Task/Semiprime/EchoLisp/semiprime.echolisp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(lib 'math)
|
||||
(define (semi-prime? n)
|
||||
(= (length (prime-factors n)) 2))
|
||||
|
||||
(for ((i 100))
|
||||
(when (semi-prime? i) (write i)))
|
||||
|
||||
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
|
||||
|
||||
(lib 'bigint)
|
||||
(define N (* (random-prime 10000000) (random-prime 10000000)))
|
||||
→ 6764578882969
|
||||
(semi-prime? N)
|
||||
→ #t
|
||||
|
||||
;; a pair n,n+1 of semi-primes
|
||||
(prime-factors 100000000041)
|
||||
→ (3 33333333347)
|
||||
(prime-factors 100000000042)
|
||||
→ (2 50000000021)
|
||||
4
Task/Semiprime/Oforth/semiprime.oforth
Normal file
4
Task/Semiprime/Oforth/semiprime.oforth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
func: semiprime(n)
|
||||
| i |
|
||||
0 2 n sqrt asInteger for: i [ while(n i /mod swap 0 &=) [ ->n 1+ ] drop ]
|
||||
n 1 > ifTrue: [ 1+ ] 2 == ;
|
||||
24
Task/Semiprime/Ring/semiprime.ring
Normal file
24
Task/Semiprime/Ring/semiprime.ring
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
prime = 1679
|
||||
decomp(prime)
|
||||
|
||||
func decomp nr
|
||||
x = ""
|
||||
sum = 0
|
||||
for i = 1 to nr
|
||||
if isPrime(i) and nr % i = 0
|
||||
sum = sum + 1
|
||||
x = x + string(i) + " * " ok
|
||||
if i = nr and sum = 2
|
||||
x2 = substr(x,1,(len(x)-2))
|
||||
see string(nr) + " = " + x2 + "is semiprime" + nl
|
||||
but i = nr and sum != 2 see string(nr) + " is not semiprime" + nl ok
|
||||
next
|
||||
|
||||
func isPrime n
|
||||
if n < 2 return false ok
|
||||
if n < 4 return true ok
|
||||
if n % 2 = 0 return false ok
|
||||
for d = 3 to sqrt(n) step 2
|
||||
if n % d = 0 return false ok
|
||||
next
|
||||
return true
|
||||
12
Task/Semiprime/Sidef/semiprime.sidef
Normal file
12
Task/Semiprime/Sidef/semiprime.sidef
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
require('ntheory');
|
||||
|
||||
func is_semiprime(n) {
|
||||
static nt = %S'ntheory';
|
||||
if (var p = [nt.trial_factor(n, 500)]) {
|
||||
return false if (p.len > 2);
|
||||
return !!nt.is_prime(p[1]) if (p.len == 2);
|
||||
}
|
||||
[nt.factor(n)].len == 2;
|
||||
}
|
||||
|
||||
say [2,4,99,100,1679,32768,1234567,9876543,900660121].grep{ is_semiprime(_) }
|
||||
37
Task/Semiprime/Swift/semiprime.swift
Normal file
37
Task/Semiprime/Swift/semiprime.swift
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import Foundation
|
||||
|
||||
func primes(n: Int) -> AnyGenerator<Int> {
|
||||
|
||||
var (seive, i) = ([Int](0..<n), 1)
|
||||
let lim = Int(sqrt(Double(n)))
|
||||
|
||||
return anyGenerator {
|
||||
while ++i < n {
|
||||
if seive[i] != 0 {
|
||||
if i <= lim {
|
||||
for notPrime in stride(from: i*i, to: n, by: i) {
|
||||
seive[notPrime] = 0
|
||||
}
|
||||
}
|
||||
return i
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func isSemiPrime(n: Int) -> Bool {
|
||||
let g = primes(n)
|
||||
while let first = g.next() {
|
||||
if n % first == 0 {
|
||||
if first * first == n {
|
||||
return true
|
||||
} else {
|
||||
while let second = g.next() {
|
||||
if first * second == n { return true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue