;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname quiz-review) (read-case-sensitive #t) (teachpacks ((lib "universe.ss" "teachpack" "2htdp") (lib "image.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "universe.ss" "teachpack" "2htdp") (lib "image.ss" "teachpack" "htdp"))))) ;; squares list-of-numbers -> list-of-numbers (check-expect (squares (list 2 3 4)) (list 4 9 16)) (define (squares alon) (map square alon)) ;; square: number -> number (define (square num) (* num num)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; first-quandrant list-of-posn -> list-of-posn ;; returns a list of positions in the first quadrant (check-expect (first-quadrant (list (make-posn 1 3) (make-posn -1 3))) (list (make-posn 1 3))) (define (first-quadrant alop) (filter in-first? alop)) ;; in-first? posn -> boolean (define (in-first? aposn) (and (> (posn-x aposn) 0) (> (posn-y aposn) 0))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; intersection list-of-numbers list-of-numbers -> list-of-numbers ;; returns a list of all numbers in both the input lists (define (intersection alon1 alon2) (filter (lambda (num) (in-list? num alon2)) alon1)) (check-expect (intersection (list 2 4 6) (list 2 3 9)) (list 2)) ;; in-list? number list-of-numbers -> boolean (define (in-list? num alon) (cond [(empty? alon) false] [else (or (= (first alon) num) (in-list? num (rest alon)))])) (check-expect (in-list? 3 (list 2 3 6 6)) true) (check-expect (in-list? 4 (list 2 3 6 6)) false) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define WS0 (make-posn 0 0)) (define WINDOW (empty-scene 800 400)) (define PLANE-IMAGE (text ">>" 20 "black")) (define (render ws) (place-image PLANE-IMAGE (posn-x ws) (posn-y ws) WINDOW)) (define (go-down ws) (make-posn (+ (posn-x ws) 2) (+ (posn-y ws) 1))) (define (landed? ws) (and (= (posn-x ws) 800) (= (posn-y ws) 400))) ;; Not needed -- just for fun (define (last-scene ws) (place-image (text "ALL DONE!" 40 "black") 300 150 WINDOW)) (big-bang WS0 (to-draw render) (on-tick go-down) (stop-when landed? last-scene))