Created
April 18, 2017 16:49
-
-
Save mattearly/0c8ec11a94cab2b2f1985032e1612344 to your computer and use it in GitHub Desktop.
This file contains 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
; extra all list elements in a list | |
(define (extract-list lst) | |
(cond ((null? lst) lst) | |
((list? (car lst)) (cons (car lst) (extract-lists (cdr lst)))) | |
(else (extract-list (cdr lst)) | |
) | |
) | |
; return number of even integers | |
(defin (count-even lst) | |
(cond ((null? lst) 0) | |
((even? (car lst)) (+ 1 ( count-even (cdr lst)))) | |
(else (count-even (cdr lst)) | |
) | |
) | |
; create pairs from elements l1 l2 | |
(define (create-pairs l1 l2) | |
(cond ((null? l1) l1) | |
((not (= (length l1) (length l2))) ()) | |
(else (cons (list (car l1) (car l2)) | |
(create-pairs (cdr l1) cdr l2)))) | |
) | |
) | |
; Makes a new list with every combination of the 2 list | |
(define (product lst1 lst2) | |
(cond | |
((null? lst1) ()) | |
((null? lst2) ()) | |
(else (append (pair-elem (car lst1) lst2) (product (cdr lst1) lst2))) | |
) | |
) | |
(define (pair-elem atm lst) | |
(cond | |
((nulL? (cdr lst)) (list atm (car lst))) | |
(else (list (list atm (car lst)) (pair-elem atm (cdr lst)))) | |
) | |
) | |
; Removes duplicates from a list | |
(define (remove-el el lst) | |
(cond ((null? lst) lst) | |
((equal? el (car lst)) (remove-el el (cdr lst))) | |
(else (cons (car lst) (remove-el el (cdr lst)))) | |
) | |
) | |
(define (remove-dups lst) | |
(cond ((null? lst) lst) | |
((member (car lst) (cdr lst)) | |
(cons (car lst) remove-dups (remove-el (car lst) (cdr lst)))))) | |
(else (cons | |
; fib recursive | |
(define (fib atm) (rec-fib 1 0 atm)) | |
(define (rec-fib n m atm) | |
(if (equal? atm 0) m (rec-fib (+ n m) n (- atm 1))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment