Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (define (prime? n)
- (define (loop i)
- (cond [(= n i) #t]
- [(= (modulo n i) 0) #f]
- [else (loop(+ i 1))]))
- (if (= n 1)
- #f
- (loop 2)))
- (define (increasing? n)
- (define lastdigit (remainder n 10))
- (define secondlastdigit (remainder (quotient n 10) 10) )
- (cond [ (< n 10) #t ]
- [ ( >= secondlastdigit lastdigit ) #f ]
- [ else (increasing? (quotient n 10))]))
- (define (toBinary n)
- (if ( < n 2)
- n
- (+ (* 10 (toBinary (quotient n 2)))
- (remainder n 2))))
- (define (toBinary* n)
- (define (loop n res bits)
- (if (= n 0)
- res
- (loop (quotient n 2)
- (+ res (* (remainder n 2) (expt 10 bits)))
- (+ bits 1))))
- (loop n 0 0))
- ;(define dx 0.0000001)
- ;(define (derive f x)
- ; (/ (- (f (+ x dx)) (f x) dx))
- ;(define (sq x) (* x x))
- ;(define (derive f)
- ; (lambda (x) (/ (- (f (+ x dx)) (f x) dx))))
- (define (accumulate op nv a b term next)
- (if (> a b)
- nv
- (op (term a)
- (accumulate op nv (next a) b term next))))
- (define (!! n)
- (accumulate * 1 (if (=(modulo n 2) 0) 2 1) n (lambda (x) x)(lambda (x) (+ 2 x))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement