Use dt.racket to finish this problem (LISP. LANGUAGE) Suppose you have a roster
ID: 3674093 • Letter: U
Question
Use dt.racket to finish this problem (LISP. LANGUAGE)
Suppose you have a roster 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.
Design a function that takes two lists of players and produces a list of matches, according to the approach described above.
;; 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)))]))
Explanation / Answer
Hi you already have the solution for the LISP language which you mentioned, For your reference i will attach the file again for your reference to the question,
;; 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)))]))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.