CS4613/Labs/02.rkt
2025-01-22 12:05:35 -04:00

26 lines
622 B
Racket

#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)