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

;;; File:
;;;   exam4.rkt
;;; Authors:
;;;   The student currently referred to as 000000
;;;   Samuel A. Rebelsky
;;;   Titus Klinge
;;; Contents:
;;;   Code and solutions for Exam 4 2017S
;;; Citations:
;;;

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

; This section is for the grader's use.

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

;    Scaled:    /100
;    Errors:  
;     Times:  
;          :  
;          :  
;          :  
;           ----
;     Total:

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

; Time Log:
;   Date        Start   Finish  Spent   Activity

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   vector-reverse!
;;; Parameters:
;;;
;;; Purpose:
;;;
;;; Produces:
;;;
;;; Preconditions:
;;;
;;; Postconditions:
;;;
(define vector-reverse!
  (lambda (vec)
    (void)))  ; STUB

; Examples/Tests:


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

; Time Log:
;   Date        Start   Finish  Spent   Activity

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   make-selector
;;; Parameters:
;;;   pred?, a unary predicate
;;; Purpose:
;;;   Create a selector for pred?.
;;; Produces:
;;;   selector, a procedure from lists to lists
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   If newlst = (selector lst) then,
;;;     Every element of newlst is in lst
;;;     (pred? val) holds for every value in newlst
;;;     (pred? lav) fails to hold for every value in lst that is not in newlst
;;;     The elements of newlst appear in the same order that they
;;;     appeared in lst.

; Examples/Tests:


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

; Time Log:
;   Date        Start   Finish  Spent   Activity

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   read-word
;;; Parameters:
;;;
;;; Purpose:
;;;
;;; Produces:
;;;
;;; Preconditions:
;;;
;;; Postconditions:
;;;
(define read-word
  (lambda (port)
    "word")) ; STUB

; Examples/Tests:


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

; Time Log:
;   Date        Start   Finish  Spent   Activity

; Time Spent: 

; Citations:

; Solution:

(define vector->tree
  (lambda (vec)
    empty)) ; STUB

; Examples/Tests:


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

; Time Log:
;   Date        Start   Finish  Spent   Activity

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;
;;; Parameters:
;;;
;;; Purpose:
;;;
;;; Produces:
;;;
;;; Preconditions:
;;;
;;; Postconditions:
;;;
(define x (lambda (y z) (apply o (make-list y z))))

; Examples/Tests:


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

; Time Log:
;   Date        Start   Finish  Spent   Activity

; Time Spent: 

; Citations:

; Provided Code

;;; Procedure:
;;;   vector-selection-sort!
;;; Parameters:
;;;   vec, a vector
;;;   less-extreme?, a binary predicate
;;; Purpose:
;;;   Sort the vector from least extreme value to most extreme value.
;;; Produces:
;;;   [Nothing; called for the side effect]
;;; Preconditions:
;;;   less-extreme? can be applied to any pair of elements in the vector.
;;;   less-extreme? is transitive.  That is, if (less-extreme? a b) and
;;;     (less-extreme? b c) then (less-extreme? a c).
;;; Postconditions:
;;;   vec contains the same elements, but perhaps permuted
;;;   vec is sorted.  That is, for all reasonable i
;;;     (less-extreme? (vector-ref vec i) (vector-ref vec (+ i 1)))
(define vector-selection-sort!
  (lambda (vec less-extreme?)
    (let kernel [(pos (- (vector-length vec) 1))]
      (when (>= pos 0)
        (let* ([index (vector-index-of-extreme vec pos less-extreme?)]
               [most-extreme (vector-ref vec index)])
          (vector-set! vec index (vector-ref vec pos))
          (vector-set! vec pos most-extreme)
          (kernel (- pos 1)))))))

; Solution:

;;; Procedure:
;;;   vector-index-of-extreme
;;; Parameters:
;;;   vec, a vector
;;;   pos, an integer
;;;   less-extreme?, a procedure that compares two values for order
;;; Purpose:
;;;   Find the index of the extreme value in the subvector of
;;;   vec at positions [0..pos].
;;; Produces:
;;;   index-of-extreme, an integer
;;; Preconditions:
;;;   pos >= 0.
;;;   (vector-length vec) > pos.
;;;   less-extreme? can be applied to any two values in vector
;;;   less-extreme? represents a transitive operation
;;; Postconditions:
;;;   For all i from 0 to pos, inclusive, either
;;;     (less-extreme? (vector-ref vec i) (vector-ref vec index-of-extreme))
(define vector-index-of-extreme
  (lambda (vec pos less-extreme?)
    pos)) ; STUB

; Examples/Tests:
