Add lab 2

This commit is contained in:
Isaac Shoebottom 2025-01-22 12:05:35 -04:00
parent e1027eb4b0
commit 89a6c652f9

25
Labs/02.rkt Normal file
View File

@ -0,0 +1,25 @@
#lang plait
;(define (middle-of-three a b c)
; (cond
; [(and (> a b) (< a c)) a]
; [(and (> b a) (< b c)) b]
; [(and (> c a) (< c b)) c]
; [(and (< a b) (> a c)) a]
; [(and (< b a) (> b c)) b]
; [(and (< c a) (> c b)) c]
; ))
(define (middle-of-three a b c)
(cond
[(eq? (max (max a b) c) a) (max b c)]
[(eq? (max (max a b) c) b) (max a c)]
[(eq? (max (max a b) c) c) (max a b)]
))
(test (middle-of-three 1 2 3) 2)
(test (middle-of-three 1 3 2) 2)
(test (middle-of-three 2 1 3) 2)
(test (middle-of-three 2 3 1) 2)
(test (middle-of-three 3 1 2) 2)
(test (middle-of-three 3 2 1) 2)