#lang racket
(require csc151)
(require rackunit)
(require rackunit/text-ui)

;;; File:
;;;   000000.rkt
;;; Authors:
;;;   The student currently referred to as 000000
;;;   Titus Klinge
;;;   Samuel A. Rebelsky
;;; Contents:
;;;   Code and solutions for Exam 1 2018S
;;; 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:

;; +----------+-------------------------------------------------------
;; | Prologue |
;; +----------+

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution:

; a.

;;; Procedure:
;;;   quadruple
;;; Parameters:
;;;
;;; Purpose:
;;;   
;;; Produces:
;;;   
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   

; b.

; c.

; d.

; Examples/Tests:
#|


|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   sort-by-substring
;;; Parameters:
;;;
;;; Purpose:
;;;   
;;; Produces:
;;;   
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   
(define sort-by-substring
  (lambda (list-of-strings start finish)
    list-of-strings)) ; STUB

; Examples/Tests:
#|

|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   
;;; Parameters:
;;;
;;; Purpose:
;;;   
;;; Produces:
;;;   
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   
(define z (lambda 
(w x y) (- 
        (+ w y (* 2 x)) 
    (min w x y) x (max w x y))))

; Examples/Tests:

#|

|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   string-remove
;;; Parameters:
;;;
;;; Purpose:
;;;   
;;; Produces:
;;;   
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   


; Test suite
(define tests-string-remove
  (test-suite
   "Tests of the string-remove procedure"
   (test-case
    "Empty string"
    (check-equal? (string-remove "" "a") ""))
   (test-case
    "Source equals pattern, singleton"
    (check-equal? (string-remove "a" "a") ""))
   (test-case
    "Source equals pattern, longer"
    (check-equal? (string-remove "alpha" "alpha") ""))))

; Examples/Tests:
#|
> (run-tests tests-string-remove)

|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution:

(define string-remove
  (lambda (source pattern)
    "")) ; STUB

; Examples/Tests:

#|

|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Supplied code

;;; Procedure:
;;;   course-available
;;; Parameters:
;;;   course, a string in "standard course info form"
;;; Purpose:
;;;   Determine the number of available slots in the given course.
;;; Produces:
;;;   available, an integer
(define course-available
  (o string->number (section substring <> 22 24)))

;;; Procedure:
;;;   course-capacity
;;; Parameters:
;;;   course, a string in "standard course info form"
;;; Purpose:
;;;   Determine the capacity of the course.
;;; Produces:
;;;   capacity, a positive integer
(define course-capacity
  (o string->number (section substring <> 25 27)))

;;; Procedure:
;;;   course-size
;;; Parameters:
;;;   course, a string in "standard course info form"
;;; Purpose:
;;;   Determine the size of the course.
;;; Produces:
;;;   size, a positive integer
(define course-size
  (lambda (course)
    (- (course-capacity course) (course-available course))))

;;; Procedure:
;;;   int->2string
;;; Parameters:
;;;   int, a non-negative integer
;;; Purpose:
;;;   Convert int to a two-digit string
;;; Produces:
;;;   str, a string
;;; Preconditions:
;;;   * 0 <= int < 100
;;; Postconditions:
;;;   * `(string-length str)` = 2
;;;   * `(string->number str)` = `(inexact->exact int)`
;;; Practica:
;;;   > (int->2string 3)
;;;   "03"
;;;   > (int->2string 42)
;;;   "42"
;;;   > (int->2string 32.0)
;;;   "32"
(define int->2string
  (lambda (int)
    (if (< int 10)
        (string-append "0" (number->string int))
        (substring (number->string int) 0 2))))
  
; Solution:

;;; Procedure:
;;;   extract-courses-by-size
;;; Parameters:
;;;   list-of-courses, a list of strings
;;;   smallest, a non-negative integer
;;;   largest, a non-negative integer
;;; Purpose:
;;;   Find all the courses whose size is between smallest and largest,
;;;   inclusive.
;;; Produces:
;;;   selected-courses, a list of strings
;;; Preconditions:
;;;   * Each string in `list-of-courses` has the "standard" course
;;;     form, illustrated by the following example.
;;;     "80631 CSC-151-02 4.00 00 32 Functional Prob Solving w/lab"
;;;     Additional details of that form may be found in assignment 3
;;;     of Grinnell's CSC 151 2018S.
;;;   * smallest <= largest
;;; Postconditions:
;;;   * `selected-courses` contains only courses whose size is between
;;;     smallest and largest, inclusive.  That is, for any string,
;;;     `course`, in `selected-courses`,
;;;     `(<= smallest (course-size course) largest)`.
;;;   * All elements of `selected-courses` appear in `list-of-courses`.
;;;   * If a course appears in `list-of-courses` and its size is
;;;     between smallest and largest, then it appears in `selected-courses`.
;;;   * `selected-courses` is sorted by capacity.  That is
;;;     For any reasonable i,
;;;     `(<= (course-capacity (list-ref selected-courses i))
;;;          (course-capacity (list-ref selected-courses (increment i))))
(define extract-courses-by-size
  (lambda (list-of-courses smallest largest)
    list-of-courses)) ; STUB

; Examples/Tests:

#|

|#

