Tressette You are given the types:  type colore = Spade | Coppa | Bastoni | Denari ;;  type valore = Ace | Two | Three | Four | Five | Six | Seven | Jack | Knight | King ;;  type mazzo = Null | Carta of carta and carta ={ c : colore ; v : valore ; mutable tl : mazzo };;  (see the picture with cards) a. Write a function points : mazzo -> int = that given a deck of cards calculates its point score. The scoring is as follows: Ace is worth 1 point; Two, Three, King, Knight, Jack are each worth 1 3 ; and the rest do not contribute the the point total. The total point score is equal to the sum of the individual points, rounded down at the end.

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter7: Input/output Technology
Section: Chapter Questions
Problem 4VE
icon
Related questions
Question

 Tressette
You are given the types:
 type colore = Spade | Coppa | Bastoni | Denari ;;
 type valore = Ace | Two | Three | Four | Five | Six |
Seven | Jack | Knight | King ;;
 type mazzo = Null | Carta of carta and carta ={ c : colore ; v
: valore ; mutable tl : mazzo };; 

(see the picture with cards)

a. Write a function points : mazzo -> int = that given a deck of cards calculates its point score. The scoring is as follows: Ace is worth 1 point; Two, Three, King, Knight, Jack are each worth 1 3 ; and the rest do not contribute the the point total. The total point score is equal to the sum of the individual points, rounded down at the end.

b. Write a function max_cards : mazzo -> mazzo = that takes a deck of cards and filters out everything except the greatest cards by value (valore) of each color. The order of cards by value is as follows: Three > Two > Ace > King > Knight > Jack > Seven > Six > Five > Four.

 

Due to the size of the output, lists like generate_cards 20 2023 are not shown, but can be generated with the use of the attached function.

 

 

DORONG
²D D
【ED
CHE
EMIENN
END END
LAMELE
pot Co.
fr
Transcribed Image Text:DORONG ²D D 【ED CHE EMIENN END END LAMELE pot Co. fr
1 # let generate_cards length seed=Random. init seed;
Array. make length 0 |> Array.fold_left (fun x y->
Carta { c = [] Spade; Coppa; Bastoni; Denari|]. (Random.
int 4); v= [] Ace; Two; Three; Four; Five; Six; Seven; Jack;
Knight; King |]. (Random.int 10); tl= x}) Null ;;
2 val generate_cards : int -> int -> mazzo = <fun>
3 # points Null ;;
4 - int = 0
5 # points (generate_cards 20 2023) ;;
6 - int = 4
#points
(generate_cards
60 2024) ;;
8 int = 20
9 # points (generate_cards 30 2020) ;;
10 - int = 9
11 # max_cards Null ; ;
7
-
12
13 # max_cards
14
21
-
: mazzo = Null
-
(generate_cards 50 2023) ;;
: mazzo = Carta {c =
= Denari; v = Three; t1 = Null}}
15 # max_cards (generate_cards 10 2026) ;;
16
: mazzo
= Carta {c Bastoni; v = Two; tl = Null}
17 # max_cards (generate_cards 10 2032) ;;
18
19 Carta
20
{c
= Denari; v = Ace;
tl = Carta {c =
Spade; v
: mazzo =
Coppa; v = Three; tl
=
Coppa; v = Ace; tl
= Ace; tl = Null}}}
= Carta {c
=
Carta {c =
Transcribed Image Text:1 # let generate_cards length seed=Random. init seed; Array. make length 0 |> Array.fold_left (fun x y-> Carta { c = [] Spade; Coppa; Bastoni; Denari|]. (Random. int 4); v= [] Ace; Two; Three; Four; Five; Six; Seven; Jack; Knight; King |]. (Random.int 10); tl= x}) Null ;; 2 val generate_cards : int -> int -> mazzo = <fun> 3 # points Null ;; 4 - int = 0 5 # points (generate_cards 20 2023) ;; 6 - int = 4 #points (generate_cards 60 2024) ;; 8 int = 20 9 # points (generate_cards 30 2020) ;; 10 - int = 9 11 # max_cards Null ; ; 7 - 12 13 # max_cards 14 21 - : mazzo = Null - (generate_cards 50 2023) ;; : mazzo = Carta {c = = Denari; v = Three; t1 = Null}} 15 # max_cards (generate_cards 10 2026) ;; 16 : mazzo = Carta {c Bastoni; v = Two; tl = Null} 17 # max_cards (generate_cards 10 2032) ;; 18 19 Carta 20 {c = Denari; v = Ace; tl = Carta {c = Spade; v : mazzo = Coppa; v = Three; tl = Coppa; v = Ace; tl = Ace; tl = Null}}} = Carta {c = Carta {c =
Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Principles of Information Systems (MindTap Course…
Principles of Information Systems (MindTap Course…
Computer Science
ISBN:
9781285867168
Author:
Ralph Stair, George Reynolds
Publisher:
Cengage Learning