;; lab 05 ;; mul : List-of-Numbers -> Number ;; multiply the numbers in the list with each other (define (mul loi) (cond [(empty? loi) 1] [(cons? loi) (* (first loi) (mul (rest loi)))])) ;; how-many: Number List-of-Numbers -> Number ;; returns back the number of times Number is found in List-of-Numbers (define (how-many n lon) (cond [(empty? lon) 0 ] [(cons? lon) (cond [(= n (first lon)) (add1 (how-many n (rest lon)))] [else (how-many n (rest lon))])])) ;; list-of-occurrences : List-of-Numbers List-of-Numbers -> List-of-Numbers ;; return a list with the number of times numbers in the first list appear ;; in the second. (define (list-of-occurrences nums lon) (cond [(empty? nums) empty] [(cons? nums) (cons (how-many (first nums) lon) ( list-of-occurrences (rest nums) lon))])) ;; list-of-occurrences-percent : List-of-Numbers List-of-Numbers -> List-of-Numbers ;; return a list with the frequency percentage of numbers in the first list appear ;; in the second. (define (list-of-occurrences-percent nums lon) (cond [(empty? nums) empty] [(cons? nums) (cons (calc-percentage (first nums) lon) (list-of-occurrences-percent (rest nums) lon))])) (define (calc-percentage n lon) (cond [(empty? lon) 0] [else (* 100 (/ (how-many n lon) (length lon)))])) (define-struct date (month day year)) ;; A Date is (make-date Month Day Year) ;; Year is a 4-digit Number e.g. 2006 ;; Day is a 2-digit number between 1 - 31 ;; Month is a 2-digit Number between 1 - 12 ;;interpretation: (make-date x y z) creates a date x/y/z (define-struct file (name size owner created)) ;; A File is a (make-file String Number String Date) ;; Date is defined at the top of this page. ;; interpretation: (make-file s n u (make-date x y z)) creates the file s with ;; size n and owner u , created on date x/y/z ;; du : List-of-Files -> Number ;; add file sizes and return the total (define (du lof) (cond [(empty? lof) 0] [(cons? lof) (+ (file-size (first lof)) (du (rest lof)))])) ;; upto-size : List-of-Files size -> List-of-Files ;; return a list of files whose size is <= to size ;; size is a Number (define (upto-size lof n) (cond [(empty? lof) empty] [(cons? lof) (cond [(filesize<=? (first lof) n) (cons (first lof) (upto-size (rest lof) n))] [else (upto-size (rest lof) n)])])) ;; filesize<=? : File Number -> Boolean ;; is the file size <= to Number ? (define (filesize<=? file n) (cond [(<= (file-size file) n) true] [else false])) ;; to-backup : List-of-Files Date -> List-of-Files ;; if file was modified since Date, then add to list of files to backup (define (to-backup lof d) (cond [(empty? lof) empty] [(cons? lof) (cond [(filedate>? (first lof) d) (cons (first lof) (to-backup (rest lof) d))] [else (to-backup (rest lof) d)])])) ;;filedate>? : File Date -> Boolean ;; file date is after Date ? (define (filedate>? file date) (cond [(date>? (file-created file) date) true] [else false])) ;;date>? : Date Date -> Boolean ;; is the first date1 greater (earlier in the past) than second date (define (date>? d1 d2) (cond [(< (date-year d1) (date-year d2)) false] [(= (date-year d1) (date-year d2)) (cond [(< (date-month d1) (date-month d2)) false] [(= (date-month d1) (date-month d2)) (cond [(< (date-day d1) (date-day d2)) false] [(= (date-day d1) (date-day d2)) false] [else true])] [else true])] [else true])) (define date1 (make-date 10 10 2005)) (define date2 (make-date 11 10 2005)) (define date3 (make-date 20 10 2005)) (define file1 (make-file "test.ss" 124 "skotthe" date1)) (define file2 (make-file "address-book" 256 "skotthe" date2)) (define file3 (make-file "index.html" 1024 "skotthe" date3))