100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

University of British Columbia CPSC 110 Assignment 7 Phase 1

Rating
-
Sold
-
Pages
10
Grade
A+
Uploaded on
15-10-2021
Written in
2021/2022

University of British Columbia CPSC 110 Assignment 7 Phase 1

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Course

Document information

Uploaded on
October 15, 2021
Number of pages
10
Written in
2021/2022
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

;; Problem Set 7 Phase 1 Solution (THIS IS A TWO-PHASE PEER GRADED PROBLEM)


NOTE!

The following applies to each of the problems in phase one of the problem set:

You are required to design each function as a 2-one-of problem.
Provide signature, purpose, stub, cross-product of types table (filled
using your examples (see next paragraph)),
and examples. DO NOT IMPLEMENT THE FUNCTION.

You must include a properly formed cross-product of types comment table to
receive credit for each problem. You must render it as text in a comment
box. It should come after the purpose. You may find it helpful to draw your
cross-product on paper for your design and then use a tool like
http://www.asciiflow.com/#Draw to help you render it.

Use your examples to fill in the cross product of types table. Remember,
the content of the table does not need to be fully-formed code. See the
videos and the 2-One-Of practice problem solutions for examples of what is
acceptable.

After you have filled in the table, you should simplify it.
As part of the simplification, assign a number to each subclass that
produces different answers. Consult the Coursera practice problem solutions
for examples of this.

Problem 1:

Suppose you have rosters for players on two opposing tennis teams, and each
roster is ordered by team rank, with the best player listed first. When both
teams play, the best players of each team play one another,
and the second-best players play one another, and so on down the line. When
one team has more players than the other, the lowest ranking players on
the larger team do not play.

In this problem you will begin to design a function that takes two lists of
players and produces a list of matches, according to the approach described
above. DO NOT IMPLEMENT THE FUNCTION.

;; Player is String
;; interp. the name of a tennis player.
(define P0 "Maria")
(define P2 "Serena")

#;
(define (fn-for-player p)
(... p))



;; Roster is one of:
;; - empty
;; - (cons Player Roster)
;; interp. a team roster, ordered from best player to worst.
(define R0 empty)
(define R1 (list "Eugenie" "Gabriela" "Sharon" "Aleksandra"))
(define R2 (list "Maria" "Nadia" "Elena" "Anastasia" "Svetlana"))

#;
(define (fn-for-roster r)
(cond [(empty? r) (...)]
[else
(... (fn-for-player (first r))

, (fn-for-roster (rest r)))]))



(define-struct match (p1 p2))
;; Match is (make-match Player Player)
;; interp. a match between player p1 and player p2, with same team rank
(define M0 (make-match "Eugenie" "Maria"))
(define M1 (make-match "Gabriela" "Nadia"))

#;
(define (fn-for-match m)
(... (match-p1 m) (match-p2 m)))



;; ListOfMatch is one of:
;; - empty
;; - (cons Match ListOfMatch)
;; interp. a list of matches between one team and another.
(define LOM0 empty)
(define LOM1 (list (make-match "Eugenie" "Maria")
(make-match "Gabriela" "Nadia")))

#;
(define (fn-for-lom lom)
(cond [(empty? lom) (...)]
[else
(... (fn-for-match (first lom))
(fn-for-lom (rest lom)))]))


Solution:
;; Roster Roster -> ListOfMatch
;; given two team rosters produce a list of matches for all pairwise ranks.
$2.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
StuviaGuides West Virgina University
Follow You need to be logged in order to follow users or courses
Sold
15169
Member since
6 year
Number of followers
8354
Documents
5312
Last sold
1 day ago
Accounting, Finance, Statistics, Computer Science, Nursing, Chemistry, Biology & More — A+ Test Banks, Study Guides & Solutions

As a Top 1st Seller on Stuvia and a nursing professional, my mission is to be your light in the dark during nursing school and beyond. I know how stressful exams and assignments can be, which is why I’ve created clear, reliable, and well-structured resources to help you succeed. I offer test banks, study guides, and solution manuals for all subjects — including specialized test banks and solution manuals for business books. My materials have already supported countless students in achieving higher grades, and I want them to be the guide that makes your academic journey easier too. I’m passionate, approachable, and always focused on quality — because I believe every student deserves the chance to excel.

Read more Read less
4.3

2134 reviews

5
1471
4
281
3
168
2
69
1
145

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions