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
11
Task/Almost-prime/EchoLisp/almost-prime-1.echolisp
Normal file
11
Task/Almost-prime/EchoLisp/almost-prime-1.echolisp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(define (almost-prime? p k)
|
||||
(= k (length (prime-factors p))))
|
||||
|
||||
(define (almost-primes k nmax)
|
||||
(take (filter (rcurry almost-prime? k) [2 ..]) nmax))
|
||||
|
||||
(define (task (kmax 6) (nmax 10))
|
||||
(for ((k [1 .. kmax]))
|
||||
(write 'k= k '|)
|
||||
(for-each write (almost-primes k nmax))
|
||||
(writeln)))
|
||||
7
Task/Almost-prime/EchoLisp/almost-prime-2.echolisp
Normal file
7
Task/Almost-prime/EchoLisp/almost-prime-2.echolisp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(task)
|
||||
|
||||
k= 1 | 2 3 5 7 11 13 17 19 23 29
|
||||
k= 2 | 4 6 9 10 14 15 21 22 25 26
|
||||
k= 3 | 8 12 18 20 27 28 30 42 44 45
|
||||
k= 4 | 16 24 36 40 54 56 60 81 84 88
|
||||
k= 5 | 32 48 72 80 108 112 120 162 168 176
|
||||
50
Task/Almost-prime/EchoLisp/almost-prime-3.echolisp
Normal file
50
Task/Almost-prime/EchoLisp/almost-prime-3.echolisp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
(lib 'match)
|
||||
(define-syntax-rule (: v i) (vector-ref v i))
|
||||
(reader-infix ':) ;; abbrev (vector-ref v i) === [v : i]
|
||||
|
||||
|
||||
(lib 'bigint)
|
||||
(define cprimes (list->vector (primes 10000)))
|
||||
|
||||
;; generates next k-almost-prime < pmax
|
||||
;; c = vector of k primes indices c[i] <= c[j]
|
||||
;; p = vector of intermediate products prime[c[0]]*prime[c[1]]*..
|
||||
;; p[k-1] is the generated k-almost-prime
|
||||
;; increment one c[i] at each step
|
||||
|
||||
(define (almost-next pmax k c p)
|
||||
(define almost-prime #f)
|
||||
(define cp 0)
|
||||
|
||||
(for ((i (in-range (1- k) -1 -1))) ;; look backwards for c[i] to increment
|
||||
(vector-set! c i (1+ [c : i])) ;; increment c[i]
|
||||
(set! cp [cprimes : [c : i]])
|
||||
(vector-set! p i (if (> i 0) (* [ p : (1- i)] cp) cp)) ;; update partial product
|
||||
|
||||
(when (< [p : i) pmax)
|
||||
(set! almost-prime
|
||||
(and ;; set followers to c[i] value
|
||||
(for ((j (in-range (1+ i) k)))
|
||||
(vector-set! c j [c : i])
|
||||
(vector-set! p j (* [ p : (1- j)] cp))
|
||||
#:break (>= [p : j] pmax) => #f )
|
||||
[p : (1- k)]
|
||||
) ;; // and
|
||||
) ;; set!
|
||||
) ;; when
|
||||
#:break almost-prime
|
||||
) ;; // for i
|
||||
almost-prime )
|
||||
|
||||
;; not sorted list of k-almost-primes < pmax
|
||||
(define (almost-primes k nmax)
|
||||
(define base (expt 2 k)) ;; first one is 2^k
|
||||
(define pmax (* base nmax))
|
||||
(define c (make-vector k #0))
|
||||
(define p (build-vector k (lambda(i) (expt #2 (1+ i)))))
|
||||
|
||||
(cons base
|
||||
(for/list
|
||||
((almost-prime (in-producer almost-next pmax k c p )))
|
||||
almost-prime)))
|
||||
|
||||
8
Task/Almost-prime/EchoLisp/almost-prime-4.echolisp
Normal file
8
Task/Almost-prime/EchoLisp/almost-prime-4.echolisp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
;; we want 500-almost-primes from the 10000-th.
|
||||
(take (drop (list-sort < (almost-primes 500 10000)) 10000 ) 10)
|
||||
|
||||
(7241149198492252834202927258094752774597239286103014697435725917649659974371690699721153852986
|
||||
440733637405206125678822081264723636566725108094369093648384
|
||||
etc ...
|
||||
|
||||
;; The first one is 2^497 * 3 * 17 * 347 , same result as Haskell.
|
||||
Loading…
Add table
Add a link
Reference in a new issue