Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Semiprime/Racket/semiprime-1.rkt
Normal file
15
Task/Semiprime/Racket/semiprime-1.rkt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#lang racket
|
||||
(require math)
|
||||
|
||||
(define (pair-factorize n)
|
||||
"Return all two-number factorizations of a number"
|
||||
(let ([up-limit (integer-sqrt n)])
|
||||
(map (λ (x) (list x (/ n x)))
|
||||
(filter (λ (x) (<= x up-limit)) (divisors n)))))
|
||||
|
||||
(define (semiprime n)
|
||||
"Determine if a number is semiprime i.e. a product of two primes.
|
||||
Check if any pair of complete factors consists of primes."
|
||||
(for/or ((pair (pair-factorize n)))
|
||||
(for/and ((el pair))
|
||||
(prime? el))))
|
||||
12
Task/Semiprime/Racket/semiprime-2.rkt
Normal file
12
Task/Semiprime/Racket/semiprime-2.rkt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#lang racket
|
||||
(require math)
|
||||
|
||||
(define (semiprime n)
|
||||
"Alternative implementation.
|
||||
Check if there are two prime factors whose product is the argument
|
||||
or if there is a single prime factor whose square is the argument"
|
||||
(let ([prime-factors (factorize n)])
|
||||
(or (and (= (length prime-factors) 1)
|
||||
(= (expt (caar prime-factors) (cadar prime-factors)) n))
|
||||
(and (= (length prime-factors) 2)
|
||||
(= (foldl (λ (x y) (* (car x) y)) 1 prime-factors) n)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue