Add 1.31
This commit is contained in:
parent
49dfe69e45
commit
43cb37c8ea
|
@ -1,3 +1,6 @@
|
|||
#! /usr/bin/racket
|
||||
#lang racket/base
|
||||
|
||||
(define (sqr n)
|
||||
(* n n))
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#! /usr/bin/racket
|
||||
#lang racket/base
|
||||
|
||||
(define (product term a next b)
|
||||
(define (iter a result)
|
||||
(if (> a b)
|
||||
result
|
||||
(iter (next a) (* (term a) result))))
|
||||
(iter a 1))
|
||||
|
||||
(define (numerator pre-applying n)
|
||||
(* pre-applying (product (lambda (x) (* x x)) 4 (lambda (x) (+ x 2)) n)))
|
||||
|
||||
(define (denominator pre-applying n)
|
||||
(* pre-applying (product (lambda (x) (* x x)) 3 (lambda (x) (+ x 2)) n)))
|
||||
|
||||
(define (fourth-of-pi n)
|
||||
(cond ((< n 1) 0)
|
||||
((even? n) (/ (numerator (* 2 (+ n 2)) n)
|
||||
(denominator 1 ( + n 1))))
|
||||
(else (/ (numerator 2 (+ n 1))
|
||||
(denominator (+ n 2) n)))))
|
||||
|
||||
(fourth-of-pi 1)
|
||||
(fourth-of-pi 2)
|
||||
(fourth-of-pi 3)
|
||||
(fourth-of-pi 60)
|
Loading…
Reference in New Issue