Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-1.l
Normal file
24
Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-1.l
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
(lib 'bigint) ;; lerge numbers
|
||||
(lib 'gloops) ;; classes
|
||||
|
||||
(define-class Rational null ((a :initform #0) (b :initform #1)))
|
||||
(define-method tostring (Rational) (lambda (r) (format "%50d / %d" r.a r.b)))
|
||||
(define-method normalize (Rational) (lambda (r) ;; divide a and b by gcd
|
||||
(let ((g (gcd r.a r.b)))
|
||||
(set! r.a (/ r.a g)) (set! r.b (/ r.b g))
|
||||
(when (< r.b 0) (set! r.a ( - r.a)) (set! r.b (- r.b))) ;; denominator > 0
|
||||
r)))
|
||||
|
||||
(define-method initialize (Rational) (lambda (r) (normalize r)))
|
||||
(define-method add (Rational) (lambda (r n) ;; + Rational any number
|
||||
(normalize (Rational (+ (* (+ #0 n) r.b) r.a) r.b))))
|
||||
(define-method add (Rational Rational) (lambda (r q) ;;; + Rational Rational
|
||||
(normalize (Rational (+ (* r.a q.b) (* r.b q.a)) (* r.b q.b)))))
|
||||
(define-method sub (Rational Rational) (lambda (r q)
|
||||
(normalize (Rational (- (* r.a q.b) (* r.b q.a)) (* r.b q.b)))))
|
||||
(define-method mul (Rational Rational) (lambda (r q)
|
||||
(normalize (Rational (* r.a q.a) (* r.b q.b)))))
|
||||
(define-method mul (Rational) (lambda (r n)
|
||||
(normalize (Rational (* r.a (+ #0 n)) r.b ))))
|
||||
(define-method div (Rational Rational) (lambda (r q)
|
||||
(normalize (Rational (* r.a q.b) (* r.b q.a)))))
|
||||
47
Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-2.l
Normal file
47
Task/Bernoulli-numbers/EchoLisp/bernoulli-numbers-2.l
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
;; Bernoulli numbers
|
||||
;; http://rosettacode.org/wiki/Bernoulli_numbers
|
||||
(define A (make-vector 100 0))
|
||||
|
||||
(define (B n)
|
||||
(for ((m (1+ n))) ;; #1 creates a large integer
|
||||
(vector-set! A m (Rational #1 (+ #1 m)))
|
||||
(for ((j (in-range m 0 -1)))
|
||||
(vector-set! A (1- j)
|
||||
(mul (sub (vector-ref A (1- j)) (vector-ref A j)) j))))
|
||||
(vector-ref A 0))
|
||||
|
||||
(for ((b (in-range 0 62 2))) (writeln b (B b))) →
|
||||
|
||||
0 1 / 1
|
||||
2 1 / 6
|
||||
4 -1 / 30
|
||||
6 1 / 42
|
||||
8 -1 / 30
|
||||
10 5 / 66
|
||||
12 -691 / 2730
|
||||
14 7 / 6
|
||||
16 -3617 / 510
|
||||
18 43867 / 798
|
||||
20 -174611 / 330
|
||||
22 854513 / 138
|
||||
24 -236364091 / 2730
|
||||
26 8553103 / 6
|
||||
28 -23749461029 / 870
|
||||
30 8615841276005 / 14322
|
||||
32 -7709321041217 / 510
|
||||
34 2577687858367 / 6
|
||||
36 -26315271553053477373 / 1919190
|
||||
38 2929993913841559 / 6
|
||||
40 -261082718496449122051 / 13530
|
||||
42 1520097643918070802691 / 1806
|
||||
44 -27833269579301024235023 / 690
|
||||
46 596451111593912163277961 / 282
|
||||
48 -5609403368997817686249127547 / 46410
|
||||
50 495057205241079648212477525 / 66
|
||||
52 -801165718135489957347924991853 / 1590
|
||||
54 29149963634884862421418123812691 / 798
|
||||
56 -2479392929313226753685415739663229 / 870
|
||||
58 84483613348880041862046775994036021 / 354
|
||||
60 -1215233140483755572040304994079820246041491 / 56786730
|
||||
|
||||
(B 1) → 1 / 2
|
||||
Loading…
Add table
Add a link
Reference in a new issue