#lang racket
(require loudhum)
(require rackunit)

;;; File:
;;;   000000.rkt
;;; Authors:
;;;   The student currently referred to as 000000
;;;   Fahmida Hamid
;;;   Samuel A. Rebelsky
;;; Contents:
;;;   Code and solutions for Exam 3 2019S
;;; Citations:
;;;

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

;; This section is for the grader's use. Please do not remove it.

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

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

;; +-----------------------------+------------------------------------
;; | Prologue (for SamR's class) |
;; +-----------------------------+

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 


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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution

;;; Procedure:
;;;   palindrome?
;;; Parameters:
;;;   str, a string
;;; Purpose:
;;;   Determines if str is a palindrome, a string that is the same
;;;   backwards or forwards.
;;; Produces:
;;;   is-palindrome?, a Boolean value
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   * If str = (list->string (reverse (string->list str))), then
;;;     is-palindrome? is true (#t).
;;;   * Otherwise, is-palindrome? is false (#f)
(define palindrome?
  (lambda (str)
    #f)) ; STUB

; Examples/Tests:
#|

|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution

;;; Procedure:
;;;   square-root
;;; Parameters:
;;;   n,
;;;   epsilon
;;; Purpose:
;;;   
;;; Produces:
;;;   
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   
(define square-root
  (lambda (n epsilon)
    n)) ; STUB

; Examples/Tests:
#|

|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   riffle
;;; Parameters:
;;;   lol, a list of lists
;;; Purpose:
;;;   To "riffle" the lists, grabbing elements from each in turn.
;;; Produces:
;;;   result, a list
(define riffle
  (lambda (lol)
    null)) ; STUB

; Examples/Tests:
#|

|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution:

; c.

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

; a. and b.

(define s (lambda (l) (lambda (p?) (let s ([a null] [b null] [c
p?]) (cond [(null? c) (list (reverse a) (reverse b))] [(l (car c))
(s (cons (car c) a) b (cdr c))] [else (s a (cons (car c) b) (cdr
c))])))))

; d.

#|
Put your explanation here
|#

; Examples/Tests:

#|

|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   vector-tally
;;; Parameters:
;;;   vec, 
;;;   pred?, 
;;; Purpose:
;;;   
;;; Produces:
;;;   
;;; Preconditions:
;;;   
;;; Postconditions:
;;;
(define vector-tally
  (lambda (vec pred?)
    0)) ; STUB

; Examples/Tests:
#|

|#

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity

; Time Spent: 

; Citations:

; Provided code:

;;; Procedure:
;;;   deep-reverse
;;; Parameters:
;;;   val, a Scheme value
;;; Purpose:
;;;   Reverses the value (most frequently, a nested list).
;;; Produces:
;;;   reversed, a Scheme value
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   * If val is not a list
;;;     reversed is val
;;;   * If val is a list
;;;       * (length reversed) = (length val)
;;;       * For each i, 0 <= i < (length reversed)
;;;         (= (deep-reverse (list-ref reversed i))
;;;            (deep-reverse (list-ref val (- (length val) i 1))))
(define deep-reverse
  (lambda (val)
    (if (list? val)
        (reverse (map deep-reverse val))
        val)))

;;; Procedure:
;;;   deep-largest
;;; Parameters:
;;;   val, a Scheme value
;;; Purpose:
;;;   Finds the largest real number in val
;;; Produces:
;;;   largest, a real number
;;; Preconditions:
;;;   val is either a real number or a deep list of real numbers.
;;; Postconditions:
;;;   * largest is one of the values in val.
;;;   * If r is a value in val, (>= largest r).
(define deep-largest
  (lambda (val)
    (if (list? val)
        (apply max (map deep-largest val))
        val)))

;;; Procedure:
;;;   deep-tally-odd
;;; Parameters:
;;;   val, a Scheme value
;;; Purpose:
;;;   Counts the number of odd values in val.
;;; Produces:
;;;   tally, an integer
;;; Preconditions:
;;;   val is either an integer or a deep list of integers
;;; Postconditions:
;;;   tally represents the number of odd integers that appear in val.
(define deep-tally-odd
  (lambda (val)
    (if (list? val)
        (apply + (map deep-tally-odd val))
        (if (odd? val) 1 0))))

; Solution:

; a.

;;; Procedure:
;;;   deep-fun
;;; Parameters:
;;;   
;;; Purpose:
;;;   
;;; Produces:
;;;   
;;; Preconditions:
;;;   
;;; Postconditions:
;;;   

; b.

; Note: The while stub has only one parameter, you will likely want
; more than one parameter.
(define deep-fun
  (lambda (val)
    val)) ; STUB

; c. 

(define deep-reverse-new
  (lambda (val)
    (deep-fun val))) ; STUB

(define deep-largest-new
  (lambda (val)
    (deep-fun val))) ; STUB

(define deep-tally-odd-new
  (lambda (val)
    (deep-fun val))) ; STUB

; d.

;;; Procedure:
;;;   deep-tally
;;; Parameters:
;;;   pred?, a predicate
;;;   val, a Scheme value
;;; Purpose:
;;;   Determine the number of values in val for which pred? holds.
;;; Produces:
;;;   tally, an integer
;;; Preconditions:
;;;   * pred? only applies to basic types (e.g., string, list, number)
;;;   * val is either a basic type or a deep list of basic types
(define deep-tally
  (lambda (pred? val)
    (deep-fun val)))

; Examples/Tests:
#|

|#

