Last active
October 24, 2015 09:00
-
-
Save mathiasverraes/963c9c0dd4985c5041cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (f a b c) | |
(sum (map sq (max2 a b c))) | |
) | |
(define (biggest a b) | |
(if (> a b) a b) | |
) | |
(define (sq a) (* a a)) | |
(define (max2 a b c) | |
(if (> a b) | |
(list a (biggest b c)) | |
(list b (biggest a c)) | |
) | |
) | |
(define (sum xs) (fold-left + 0 xs)) | |
(define (good-enough? guess x) | |
(< | |
(abs (- (* guess guess guess) x)) | |
0.001 | |
) | |
) | |
(define (improve guess x) | |
(/ | |
(+ | |
(/ | |
x | |
(sq guess) | |
) | |
(* 2 guess) | |
) | |
3 | |
) | |
) | |
(define (cbr x) (cbr' 5 x)) | |
(define (cbr' guess x) | |
(if (good-enough? guess x) | |
guess | |
(cbr' (improve guess x) x) | |
) | |
) | |
(define (add1 x) (+ x 1)) | |
(define (f n) | |
(if (< n 3) | |
n | |
(+ | |
(* 1 (f (- n 1))) | |
(* 2 (f (- n 2))) | |
(* 3 (f (- n 3))) | |
) | |
) | |
) | |
(define (formula x y z) | |
(+ x (* 2 y) (* 3 z)) | |
) | |
(define (first3 xs) | |
(list | |
(car xs) | |
(car (cdr xs)) | |
(car (cdr (cdr xs))) | |
) | |
) | |
(define (accf acc) | |
(if (> 3 (length acc)) | |
(cons (+ 1 (car acc)) acc) | |
(cons (formula (first3 acc)) acc) | |
) | |
) | |
(cons (formula (first3 (list 3 2 1))) (list 3 2 1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define lorem | |
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." | |
) | |
;; tests | |
;; (equal? (wrap "" 70) "") | |
;; (equal? (wrap "socrates" 20) "socrates") | |
;; (equal? (wrap "Looong" 5) "Looon\ng") | |
(define (split xs pos) | |
(cond | |
((equal? pos 0) | |
(list () xs)) | |
((null? xs) | |
(list () ())) | |
((< (length xs) pos) | |
(list xs ())) | |
(else | |
(let ((acc (split (cdr xs) (- pos 1)))) | |
(list | |
(cons (car xs) (car acc)) | |
(cdr acc) | |
) | |
) | |
) | |
) | |
(define (take xs n) | |
(cond | |
((equal? n 0) | |
()) | |
((null? xs) | |
(list)) | |
((< (length xs) n) | |
xs) | |
(else | |
(cons (car xs) (take (cdr xs) (- n 1)))) | |
) | |
) | |
(define lll (list 1 2 3 4 5 6)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment