;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname lab4) (read-case-sensitive #t) (teachpacks ((lib "testing.ss" "teachpack" "htdp") (lib "world.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "testing.ss" "teachpack" "htdp") (lib "world.ss" "teachpack" "htdp"))))) ;Amber and Jacob ;Lab 4 ;Contract: within?:number number number -> bool ;Purpose: Determine if a point (x,y) is within a circle of radius r centered at the origin. ;Examples: (within? 1 1 1) should produce false ; (within? 0 5 5) should produce true ; (within? 0 0 20) should produce true (define (within? x y r) (<= (+ (* x x) (* y y)) (* r r))) ;Test cases ;(check-expect (within? 1 1 1) false) ;(check-expect (within? 0 5 5) true) ;(check-expect (within? 0 0 20) true) ;Contract new-price: number number -> number ;Purpose: Given an original price and a number of weeks the item has been in the store at a 25% discount per week starting the third week and ending the fifth week, output the current price of the item. ;Examples: (new-price 100 3) should produce 75 ; (new-price 200 4) should produce 100 ; (new-price 300 5) should produce 75 (define (new-price old-price weeks) (cond [(>= weeks 5) (* (- 1 0.75) old-price)] [(>= weeks 4) (* (- 1 0.50) old-price)] [(>= weeks 3) (* (- 1 0.25) old-price)] [else old-price])) ;Test cases ;(check-expect (new-price 100 3) 75) ;(check-expect (new-price 200 4) 100) ;(check-expect (new-price 300 5) 75) ; Contract right-triangle?: number number number -> boolean ; Prupose: Given the three sides of a triangle, output whether a right triangle can be created. ;Examples (right-triangle? 3 4 5) should produce true ; (right-triangle? 7 25 24) should produce true ; (right-triangle? 1 1 1) should produce false (define (right-triangle? side1 side2 side3) (or (= (+ (* side1 side1) (* side2 side2)) (* side3 side3)) (= (+ (* side2 side2) (* side3 side3)) (* side1 side1)) (= (+ (* side1 side1) (* side3 side3)) (* side2 side2)))) ;Test cases ;(check-expect (right-triangle? 3 4 5) true) ;(check-expect (right-triangle? 7 25 24) true) ;(check-expect (right-triangle? 1 1 1) false) ;Contract: smart-dot: Number Number -> Scene ;Purpose: Draw a dot with radius 10 at coordinates (x,y). If it overlaps with the white circle with radius 75 pixels in the center of the 200x200 black square, color it green. Otherwise, color it red. ;Examples: (smart-dot 40 40) should produce a green dot touching the top left edge of the white circle ; (smart-dot 12 100) should produce a red dot on the left edge of the square ; (smart-dot 0 0) should produce nothing ; (smart-dot 100 100) should produce a green dot in the center of the white circle (define (square x) (* x x)) (define (smart-dot x y) (place-image (cond [(<= (+ (square (- x 100)) (square (- y 100))) (square 85)) (circle 10 'solid 'green)] [(or (< x 10) (< y 10) (> x 190) (> y 190)) (circle 1 'solid 'black)] [else (circle 10 'solid 'red)]) x y (place-image (circle 75 'solid 'white) 100 100 (place-image (nw:rectangle 200 200 'solid 'black) 0 0 (empty-scene 200 200))))) ;Test cases ;(smart-dot 40 40) "should produce a green dot touching the top left edge of the white circle" ;(smart-dot 12 100) "should produce a red dot on the left edge of the square" ;(smart-dot 0 0) "should produce nothing but the circle" ;(smart-dot 100 100) "should produce a green dot in the center of the white circle" ;Contract: randon-smart-dot: number -> scene ;Purpose: Draw a dot using the smart-dot function from above that is confined with-in the 200x200 pixel as it generates random x and y values. ; Examples: (random-smart-dot 42) should produce a dot somewhere in the square ; (random-smart-dot 90)should produce a dot somewhere in the square (define (random-smart-dot x) (smart-dot (+ (random 181) 10) (+(random 181) 10))) ;Test cases: ;(random-smart-dot 42) "should produce a dot somewhere in the square" ;(random-smart-dot 90)"should produce a dot somewhere in the square" ;(random-smart-dot 111)"should produce a dot somewhere in the square" ;run-simulation function :) (run-simulation 200 200 .5 random-smart-dot) (generate-report) ;Desert ;Number 1 ;Contract: linear-progression: number number number -> boolean ;Purpose: GIven three numbers determine if they form a linear arithmetic progression.If true is returned then they form an artithmetic progression, but if false, then they do not. Also, the numbers are not in a specific order, so we cannt they are in ascending or descending order. ; Examples: (linear-progression 9 15 4) should produce false ; (linear-progression 15 5 10) should produce true (define (linear-progression x y z) (or (= (- x y) (- y z)) (= (- x z) (- z y)) (= (- y x) (- x z)))) ;Test cases: ;(check-expect (linear-progression 9 15 4) false) ;(check-expect (linear-progression 15 5 10) true) ;(check-expect (linear-progression 1 2 3) true) ;(check-expect (linear-progression 11 5 17) true) ;Contract: evaulate-card: number/symbol -> number ;Purpose: given a number from 2-14 or a symbol from {'J, 'Q, 'K, 'A}, output the value of the corresponding card in poker, with aces high. ;Examples: (evaluate-card 2) should produce 2 ; (evaluate-card 'J) should produce 11 ; (evaluate-card 'Q) should produce 12 ; (evaluate-card 'K) should produce 13 ; (evaluate-card 'A) should produce 14 ; (evaluate-card 'F) should produce an error (define (evaluate-card card) (cond [(and (number? card) (<= 2 card) (<= card 14)) card] [(symbol=? card 'J) 11] [(symbol=? card 'Q) 12] [(symbol=? card 'K) 13] [(symbol=? card 'A) 14])) ;Test cases (check-expect (evaluate-card 2) 2) (check-expect (evaluate-card 'J) 11) (check-expect (evaluate-card 'Q) 12) (check-expect (evaluate-card 'K) 13) (check-expect (evaluate-card 'A) 14) ;(evaluate-card 'F) "should produce an error" ;Contract: evaluate-hand: number/symbol number/symbol number/symbol number/symbol number/symbol -> symbol ;Purpose: given a sorted poker hand, output as a symbol the name of the hand you have. ;Examples: (evaluate-hand 6 6 'J 'J 'K ) should produce 'two-pairs ; (evaluate-hand 2 3 10 10 10 ) should produce 'three-of-a-kind ; (evaluate-hand 4 4 4 4 5 ) should produce 'four-of-a-kind ; (evaluate-hand 'J 'J 'J 10 10 ) should produce 'full-house ; (evaluate-hand 8 9 10 'J 'Q ) should produce 'straight ; (evaluate-hand 5 7 8 8 10 ) should produce 'pair ; (evaluate-hand 3 5 7 8 'Q) should produce 'nothing