100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary CPSC 110 PSET 10 SOLUTION $20.49   Add to cart

Summary

Summary CPSC 110 PSET 10 SOLUTION

8 reviews
 2511 views  23 purchases
  • Course
  • Institution

CPSC 110 PSET 10 SOLUTION

Preview 2 out of 5  pages

  • July 11, 2021
  • 5
  • 2020/2021
  • Summary

8  reviews

review-writer-avatar

By: miamurakun • 9 months ago

review-writer-avatar

By: emilydickson • 1 year ago

review-writer-avatar

By: xuzichun0525 • 1 year ago

review-writer-avatar

By: luckyisepicpanda2222 • 1 year ago

review-writer-avatar

By: andychen3 • 1 year ago

review-writer-avatar

By: varneegatheva • 2 year ago

review-writer-avatar

By: gabematu28 • 2 year ago

Show more reviews  
avatar-seller
;; The first three lines of this file were inserted by DrRacket. They record
metadata
;; about the language level of this file in a form that our tools can easily
process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname pset-10-solution)
(read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-
decimal #f #t none #f () #t)))
;; DO NOT PUT ANYTHING PERSONALLY IDENTIFYING BEYOND YOUR CWL IN THIS FILE.
;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU AND, IF YOU HAVE ONE, YOUR
;; PARTNER.
;;
(require spd/tags)

(@assignment pset-10); Do not edit or remove this tag



(@problem 1)

(@htdf max-num-repeats)
(@signature (listof String) -> Natural)
;; produce maximum number of times same string appears consecutively in los0
(check-expect (max-num-repeats empty) 0)
(check-expect (max-num-repeats (list "cat")) 1)
(check-expect (max-num-repeats (list "cat" "bird" "dog")) 1)
(check-expect (max-num-repeats (list "cat" "cat" "bird" "dog")) 2)
(check-expect (max-num-repeats (list "cat" "cat" "bird" "dog" "dog" "dog"))
3)
(check-expect (max-num-repeats (list "cat" "cat" "cat"
"bird"
"boy" "boy" "boy"
"toy" "toy" "toy" "toy" "toy"
"trick"
"zebra" "zebra" "zebra" "zebra"))
5)

(@template (listof String) accumulator)

(define (max-num-repeats los0)
;; prev is String: the previous first string in list
;; curr is Natural: number of times prev has been seen so far
;; rsf is Natural: maximum number of times a string has been seen so far
(local [(define (fn-for-los los prev curr rsf)
(cond [(empty? los) (max curr rsf)]
[else
(if (string=? (first los) prev)
(fn-for-los (rest los) (first los) (add1 curr) rsf)
(fn-for-los (rest los) (first los) 1 (max curr rsf)))]))]
(if (empty? los0)
0
(fn-for-los (rest los0) (first los0) 1 0))))

(@problem 2)

(@htdf list-range)
(@signature (listof Integer) -> Natural)
;; produce the difference between the max and min integer in the list
;; CONSTRAINT: loi0 has at least one element
(check-expect (list-range (list 100)) 0)

, (check-expect (list-range (list 2 -5 -10 50 80)) 90)
(check-expect (list-range (list 5000 -5 -100 50 0)) 5100)
(check-expect (list-range (list 3 8 1 2 9 4 2 3 -5)) 14)
(check-expect (list-range (list -5000 3 2 2 4 5000 4 2 3)) 10000)
(check-expect (list-range (list 400 500 500 400)) 100)

(@template (listof Integer) accumulator)

(define (list-range loi)
;; max-rsf is Integer: maximum integer seen so far
;; min-rsf is Integer: minimum integer seen so far
(local [(define (fn-for-loi loi max-rsf min-rsf)
(cond [(empty? loi) (- max-rsf min-rsf)]
[else
(fn-for-loi (rest loi)
(max (first loi) max-rsf)
(min (first loi) min-rsf))]))]
(fn-for-loi (rest loi) (first loi) (first loi))))



(@problem 3)

(@htdf in-alphabetical-order?)
(@signature (listof String) -> Boolean)
;; produce true if list is sorted in order according to string-ci<=?
(check-expect (in-alphabetical-order? empty) true)
(check-expect (in-alphabetical-order? (list "a")) true)
(check-expect (in-alphabetical-order? (list "All" "bees" "Feel" "HAPPY")) true)
(check-expect (in-alphabetical-order? (list "aaaaa" "bb" "dd" "ccc")) false)

(@template (listof String) accumulator)

(define (in-alphabetical-order? los0)
;; prev is String: previous string in los
(local [(define (fn-for-los los prev)
(cond [(empty? los) true]
[else
(if (string-ci<=? prev (first los))
(fn-for-los (rest los) (first los))
false)]))]
(if (empty? los0)
true
(fn-for-los (rest los0) (first los0)))))



;;
;; Please read through the data definition introduced in Problem Set 6
;; for a Course.
;;

(@htdd Course)
(define-struct course (number credits dependents))
;; Course is (make-course Natural Natural ListOfCourse)
;; interp. a course with a course number,
;; the number of credits the course is worth,
;; a list of courses that have this course as a pre-requisite

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller travissmith1. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $20.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

76449 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$20.49  23x  sold
  • (8)
  Add to cart