Exercise 5.1.3: (back)

;; check-guess3: number number number number -> { 'TooSmall 'Perfect 'TooLarge }
;; guess1 is the least significant digit and guess3 is the most significant digit
(define (check-guess3 guess1 guess2 guess3 target)
  (cond
    [(< (join-guess guess1 guess2 guess3) target) 'TooSmall]
    [(= (join-guess guess1 guess2 guess3) target) 'Perfect]
    [(> (join-guess guess1 guess2 guess3) target) 'TooLarge]))


;; join-guess: number number number -> symbol
(define (join-guess num1 num2 num3)
  (+ (digit1 num1) (digit10 num2) (digit100 num3)))


;; digit1: number -> number
(define (digit1 number)
  (* 1 number))

  
;; digit10: number -> number
(define (digit10 number)
  (* 10 number))

  
;; digit100: number -> number
(define (digit100 number)
  (* 100 number))
  

;; Tests  
> (check-guess3 1 2 3 200)
'TooLarge

> (check-guess3 3 2 1 200)
'TooSmall

> (check-guess3 3 2 1 123)
'Perfect