A) (define (count l) (if (null? l)0 ( + 1 (count (cdr l)))))
B) (define (findmax l) (if (null? (cdr l)) (car l)
(if (> (car l) (findmax (cdr l)))(car l)
(findmax (cdr l)))))
C) (define (readnums) (let ((x (read))) (if (= x 0) '() (cons x (readnums)))))
D) (define (findmax l) (if (null? (cdr l)) (car l)
(if (> (car l) (findmax (cdr l)))(car l)
(findmax (cdr l)))))
(define (findmin l) (if (null? (cdr l)) (car l)
(if (< (car l) (findmin (cdr l))) (car l) (findmin (cdr l)))))
(define (readnums) (let ((x (read)))
(if (= x 0) '() (cons x (readnums)))))
(define (minmax l) (define x l) (cons (findmin x) (list (findmax x))))
/* Prints out the Min then Max into new list */
E) Quick Sort Scheme
F) Merge Sort Scheme
G) Haskell
pythriple n = [(x,y,z) | x <- [1..n], y <- [x..n], z <- [y..n], x^2 + y^2 == z^2]
Scheme SRFI-42
(define (pythriple n) (list-ec (:range x 1 n)
(:range y x n)
(:range z y n)
(if (= (* z z) (+ (* x x) (* y y)))
(list x y z))))
H) 8x
(define square (lambda (x) (* x x)))
(define twice (lambda (f) (lambda (x) (f (f x)))))
I) (define ((inc_n n) x)
(cond [(> x 0) ((inc_n (+ n 1)) (- x 1))]
[else n]))
No comments:
Post a Comment