#lang racket
(require gigls/unsafe)
(require rackunit)
(require rackunit/text-ui)

;;; File:
;;;   exam3.rkt
;;; Authors:
;;;   The student currently referred to as 000000
;;;   Charlie Curtsinger
;;;   Samuel A. Rebelsky
;;; Contents:
;;;   Code and solutions for Exam 3 2015F.
;;; Citations:
;;;

; +---------+--------------------------------------------------------
; | Grading |
; +---------+

; This section is for the grader's use.

; Problem 1: 
; Problem 2:
; Problem 3:
; Problem 4:
; Problem 5:
; Problem 6:
;           ----
;     Total:

;    Scaled:
;    Errors:
;     Times:
;          :
;          :
;          :
;           ----
;     Total:


; +-----------+------------------------------------------------------
; | Problem 1 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   
;;; Parameters:
;;;   x, a real number
;;;   n, a non-negative integer 
;;; Purpose:
;;;    
;;; Produces:
;;;   NAME, a TYPE
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   
(define fun
  (lambda (x n)
    (cond
      [(zero? n)
       1]
      [(odd? n)
       (* x (fun x (- n 1)))]
      [else
       (square (fun x (/ n 2)))])))

;;; Identifier:
;;;   fun-tests
;;; Type:
;;;   Test suite.
;;; Value:
;;;   Tests for fun.
(define fun-tests
  (test-suite
   "Tests for fun"
   (test-case "fun(0,0) = 1"
              (check-= (fun 0 0) 1 .0001))))
    
; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 2 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   irgb-furthest
;;; Parameters:
;;;   color, 
;;;   colors, 
;;; Purpose:
;;;    
;;; Produces:
;;;   NAME, a TYPE
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   
(define irgb-furthest
  (lambda (color colors)
    (let kernel ([remaining (cdr colors)]
                 [guess (car colors)])
      color)))

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 3 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   string->words
;;; Parameters:
;;;   str, a string
;;; Purpose:
;;;   Split str into a list of individual words.
;;; Produces:
;;;   words, a list of strings
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   If we join together all of the words in words, separating them
;;;     with spaces we end up with str.
;;;   No word in words contains a space.
(define string->words
  (lambda (str)
    null))

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 4 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   
;;; Parameters:
;;;   
;;; Purpose:
;;;    
;;; Produces:
;;;   NAME, a TYPE
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   
(define f (lambda (a b c) (list->string (map (o (l-s string-ref a) (l-s + b)) (iota (- c b))))))

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 5 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   turtle-script!
;;; Parameters:
;;;   turtle, a turtle
;;;   script, a list of one-parameter functions
;;; Purpose:
;;;   Have turtle execute the actions in script one by one
;;; Produces:
;;;   turtle, the same turtle
;;; Preconditions:
;;;   script has the form '(action-1! ... action-n!)
;;;   Each action is a procedure of one parameter that takes a turtle
;;;     as input.
;;; Postconditions:
;;;   The following actions have been executed in sequence.
;;;     (action-1! turtle)
;;;     (action-2! turtle)
;;;     ...
;;;     (action-n! turtle)
(define turtle-script!
  (lambda (turtle script)
    turtle))

; Examples/Tests:


; +-----------+------------------------------------------------------
; | Problem 6 |
; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   turtle-tree!
;;; Parameters:
;;;   turtle, 
;;;   trunk-length, 
;;;   branches, 
;;;   levels, 
;;; Purpose:
;;;    
;;; Produces:
;;;   
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   
(define turtle-tree!
  (lambda (turtle trunk-length branches levels)
    (void)))

; Examples/Tests:


; ===================================================================

; BEFORE PRINTING, PLEASE MAKE A *SEPARATE* COPY OF YOUR CODE AND
; REMOVE EVERYTHING BELOW THIS LINE.

; PLEASE DO NOT ADD ANYTHING BELOW THIS POINT.

;;; Procedure:
;;;   irgb-distance
;;; Parameters:
;;;   color1, an integer-encoded RGB color
;;;   color2, an integer-encoded RGB color
;;; Purpose:
;;;   Find the distance between color1 and color2, using some simple
;;;   metric for distance.
;;; Produces:
;;;   distance, a non-negative real number
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   If color1=color2, then distance is 0
;;;   For any three colors, a, b, and c, if 
;;;     (irgb-distance a b) < (irgb-distance b c)
;;;   then a is likely to be perceived as being closer to b than c.
;;; Plus:
;;;   irgb-distance is commutative.  That is, for any two colors, a and b,
;;;     (irgb-distance a b) = (irgb-distance b a)
(define irgb-distance
  (lambda (color1 color2)
    (+ (square (- (irgb-red color1) (irgb-red color2)))
       (square (- (irgb-green color1) (irgb-green color2)))
       (square (- (irgb-blue color1) (irgb-blue color2))))))

;;; Procedure:
;;;   set-up-turtle
;;; Parameters:
;;;   [None]
;;; Purpose:
;;;   Create a world, a turtle, set the brush to a fine line, and position 
;;;   the turtle at the bottom middle of the image facing up.
;;; Produces:
;;;   turtle, a turtle
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   A new image is shown.
;;;   turtle is placed on that image.
;;;   The turtle is facing northward.  (turtle-angle turtle = 270)
(define set-up-turtle
  (lambda ()
    (let* ([world (image-show (image-new 300 200))]
           [tommy (turtle-new world)])
      (turtle-turn! tommy -90)
      (turtle-teleport! tommy 150 200)
      (turtle-set-brush! tommy "2. Hardness 100" 0.15)
      tommy)))
