Escolar Documentos
Profissional Documentos
Cultura Documentos
This lab makes use of the following structure and data definitions:
(define-struct card (value suit))
;; A card is a structure (make-card v s), where
;; v is an integer in the range from 1 to 10 and
;; s is a symbols from the set 'hearts,
;; 'diamonds, 'spades, and 'clubs.
1. Complete the function value-of-hand which consumes three cards and produces the
value of the hand in the following way:
If all three cards are of the same suit, then the value is twice the sum of the values of
the three cards (e.g. (value-of-hand (make-card 3 diamonds) (make-card 2
diamonds) (make-card 9 diamonds)) produces 28);
If exactly two cards have the same suit, then the value is the sum of the values of the
cards with the matching suits (e.g. (value-of-hand (make-card 3 diamonds)
(make-card 2 hearts) (make-card 9 diamonds)) produces 12); or
The value is 0 if the three suits are different (e.g. (value-of-hand (make-card 3
diamonds) (make-card 2 hearts) (make-card 9 clubs)) produces 0).
2. Create a function safe-make-cal that consumes two integers, m and d, and either produces the
cal with month m and d, if m and d satisfy the necessary requirements in the definition,
or impossible if there is no calendar entry with month m and day d in a non-leap year
calendar. For example, (safe-make-cal 3 4) will produce impossible and (safe-make-
cal 2 5) will produce (make-cal 2 5).
3. Create a function cal->string that consumes a cal structure, and produces a string
representing the calendar entry. For example, (cal->string (make-cal 1 1)) produces 1st
of January, (cal->string (make-cal 4 11) produces 11th of April, and (cal-
>string (make-cal 12 21)) produces 21st of December.
4. Create a function overlap? that consumes two interval structures, int1 and int2, and produces
true if there are any dates included in both intervals and false otherwise. Note: an interval is
considered to include both the starting and ending dates. For example, (overlap? Reelsdates
comedydates) will produce false and (overlap? reelsdates (make-interval cal3-4
cal3-8)) will produce true.
6. Create a function better-festival that consumes two festival structures, fest1 and fest2,
and produces the name of the better festival, or the name of fest1 if they are equally good. The
order of festivals from best to worst is as follows: free and in Waterloo, free but not in Waterloo,
in Waterloo but not free, anything else. A festival is in Waterloo if the location is exactly the
string "Waterloo". For example, (better-festival blues buskers) will produce "Busker
Carnival" and (better-festival reels comedy) will produce "Rainbow Reels".