From 89a6c652f9c475c77ded46957379faaa75be8fd7 Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Wed, 22 Jan 2025 12:05:35 -0400 Subject: [PATCH] Add lab 2 --- Labs/02.rkt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Labs/02.rkt diff --git a/Labs/02.rkt b/Labs/02.rkt new file mode 100644 index 0000000..ca6428d --- /dev/null +++ b/Labs/02.rkt @@ -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)