Skip to main content

CSC 151 2019S, Class 14: Discuss exam 1

Overview

  • Preliminaries
    • Notes and news
    • Upcoming work
    • Extra credit
    • Questions
  • Some general issues
  • Some problems of interest
  • Concluding notes

Preliminaries

News / Etc.

  • I emailed about six of you at 10:00 p.m. on Sunday night to ask you to turn in your epilogues. It depresses me that five of the six replied within five minutes. (Or is just that you read email on your cell phones?)
  • Mentor sessions Wednesday 8-9 p.m., Thursday 8-9 p.m., Sunday 5-6 p.m.
  • Today’s class is intended as a chance for you to learn a bit about the grading on exam 1 and some solutions. I’ve sent you a much too long answer key that you may want to read, too.
  • For the rest of this week, I will be attending the 50th Annual SIGCSE Technical Symposium on Computer Science Education. (It’s in Minneapolis, so the weather is likely to be worse than here.) Dr. Stone will be covering class on Wednesday and Friday. I will be available via email off and on throughout each day.
  • Since I’ll be away, I do not have office hours this week.
  • Greetings to our ill students who claim that they are reading the eboard during class.
  • Email Sam if you have a question.

Upcoming work

  • Reading for Wednesdays
  • Assignment 5 due Tuesday.
  • Flash cards due Wednesday at 8:00 p.m.
    • Covers Wednesday/Friday/Monday classes
  • No lab writeup today!
  • Quiz Friday: Randomness and Local Bindings

Extra Credit

I would certainly appreciate suggestions of other extra credit activities (preferably via email).

Extra credit (Academic/Artistic)

Extra credit (Peer)

Extra credit (Wellness)

  • Student wellness fair, Tuesday, 5-7 pm, JRC 1st and second floors.

Extra credit (Wellness, Regular)

  • 30 Minutes of Mindfulness at SHACS every Monday 4:15-4:45
  • Any organized exercise. (See previous eboards for a list.)
  • 60 minutes of some solitary self-care activities that are unrelated to academics or work. Your email reflection must explain how the activity contributed to your wellness.
  • 60 minutes of some shared self-care activity with friends. Your email reflection must explain how the activity contributed to your wellness.

Extra credit (Misc)

Other good things

  • Neverland players this weekend (Friday 8:30, Sat 2:00 and 7:30, and Sun 2:00)

Questions

Broad notes on the exam

It was a challenging exam and most of you did quite well. Congratulations!

When you get your exam back you’ll see notes at the top.

  • Sam is a cruel [fill in word], so if your exam won’t run, or if you didn’t change numbers, you lose points.
  • Sam limits his cruelty on this exam. In the far future, if you forget spaces in your codek he’ll likely take off points.

The examples section is important! Try a few cases to show yourself and me that your procedure works!

  • They can be a good place to show places in which your code does not work.
  • They can help you identify places in which your code does not work.

Note: Helpers often make design user. Remember: “Uh stands for “use helpers””

Sam talked about this header while stepping through it.

#lang racket
(require loudhum)
(require 2htdp/image)

;; SAMR SAYS: I will preface all of my comments two semicolons, a space,
;; and the words "SAMR SAYS".

;;; File:
;;;   000000.rkt
;;; Authors:
;;;   The student currently referred to as 000000

;; SAMR SAYS: You should have changed the 000000's.  Reading instructions
;; is important.

;;;   Jo Smith

;; SAMR SAYS: You may lose points for making your exam non-anonymous.

;;; Contents:
;;;   Code and solutions for Exam 1 2019S
;;; Citations:
;;;

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

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

;; Problem 1: 11
;; Problem 2:  8
;; Problem 3:  7
;; Problem 4: 10
;; Problem 5:  6
;; Problem 6:  9
;;           ----
;;     Total: 51/60

;;    Scaled: 85/100
;;    Errors:  4
;;     Times:  2
;;    000000: -1
;; Won't run: -2
;;          :
;;           ----
;;     Total: 58/100  -> 67/100 with TMTL

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

; Time Log:
;   Date        Start   Finish  Elapsed Activity
;   2019-02-25  08:00   09:00   1:00    Enjoyed reading problems
;   2019-02-25  18:00   18:15   0:15    Emailed prologue to sam

; Time Spent: 1:15

Documentation

  • Two problems to document, sublist and string-reverse
  • Preconditions and postconditions are hard. We need practice.
;;; Procedure:
;;;   sublist   
;;; Parameters:
;;;   lst, a list
;;;   start, a number
;;;   end, a number
;;; Purpose:
;;;   Pulls the sublist from a list that starts at start and ends
;;;   at end.
;;; Produces:
;;;   sub, a list

;;;   SAMR SAYS: name, type

;;; Preconditions:
;;;   * start >= 0
;;;   * 0 <= end <= (length lst)
;;;   * start <= end
;;;   * lst can't be empty (or maybe it can if start and end are 0)
;;;   * start and end must be exact integers
;;; Postconditions:
;;;   * sub is a sublist of lst.
;;;   * start and end help specify that sublist.
;;;   * element 0 of sub is element start of lst
;;;   * element 1 of sub is element start+1 of lst
;;;   * element 2 of sub is element start+2 of lst
;;;   * ...
;;;   * (length sub) = (- end start)

Simplified preconditions:

;;;   * 0 <= start <= end <= (length lst)

Tradeoff between parameters and the preconditions

;;; Parameters:
;;;   start, a non-negative exact integer
;;;   (now our preconditions need not state that)
;;; Parameters:
;;;    start, a non-negative exact integer less than finish

Mathy postconditions

;;; Postconditions:
;;;   For all i, 0 <= i < (length sub)
;;;     (list-ref sub i) = (list-ref lst (+ start i))
  • Please choose names that are helpful to the reader, like lst, start and end, and not a, b, and c, and certainly not num, str, and lst. (Also not :-/, /-: and ///\\\\\\.
  • Postconditions help resolve those ambiguities.
  • Please don’t use names of extant procedures for parameters and procedures.
;;; Procedure:
;;;   string-reverse   
;;; Parameters:
;;;   str, a string
;;; Purpose:
;;;   Reverses a string
;;; Produces:
;;;   reversed, a string
;;; Preconditions:
;;;   str must be nonempty
;;; Postconditions:
;;;   For all i, 0 <= i < (string-length str)
;;;     character i in reversed is character length-i-1 in str

A clever but not sufficient postconditions

;;;    (string-reverse reversed) = str
(define string-reverse
  (lambda (str)
     str))

Sam attempts question 5, live

; Thought process:
;   Start with a backtick
;   lots of not-backticks
;   End with a backtick
(define markdown-code
  (lambda (str)
    (regexp-replace* #px"`([^`]*)`"
                     str
                     "<code>\\1</code>")))
> (markdown-code "I wrote `markdown-code`.")
"I wrote <code>markdown-code</code>."
> (markdown-code "`markdown-code` takes one parameter, `str`.")
"<code>markdown-code</code> takes one parameter, <code>str</code>."
> (markdown-code "Here's a backtick: `.")
"Here's a backtick: `."
; Thought process for emphasis.
;   _ for em is a lot like ` for code
(define markdown-em 
  (lambda (str)
    (regexp-replace* #px"_([^_]*)_"
                     str
                     "<em>\\1</em>")))

A shorter version

(define markdown-em
  (section regexp-replace* #px"_([^_]*)_" <> "<em>\\1</em>"))

What about two underscores? It feels similar.

(define markdown-strong
  (lambda (str)
    (regexp-replace* #px"__([^__]*)__"
                     str
                     "<strong>\\1</strong>")))

What is #px"[ab]"? a or b

What is #px"[^ab]"? Anything one character that’s not a or b.

What is #px"[^__]"? Anything that’s not underscore. (The goal was likely “not two underscores”, but set notation does not work for that.)

Here’s a likely pattern for “not two underscores”: #px"(([^_]|_[^_])*)"

How do we combine the two?

(define markdown-emphasis
   (o markdown-em
      markdown-strong))

I care about you all, but …

  • I received two exams that are essentially identical.
  • I received a few exams in which I got a different output than the example. Forging output of a computer program is academically dishonest.
  • There’s one other potential case.
  • CAS policy is that I cannot return exams until I report these issues. I hope to do so in the next day or so.