You are given the types: type colore-Spade type valore- Ace Seven Jack | Coppa | Bastoni | Denari;; Two Three Four Five | Six | Knight | King;; a type mazzo-Null | Carta of carta and carta={c: colore; v : valore; mutable tl: mazzo) ;; HE Write a function points: mazzo -> int= The given a deck of cards it calculates the point score of it. The scoring is as follows: Ace is worth 1 point; Two, Three, King, Knight, Jack are each worth; and the

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Ocaml, functional programming task. 

You are given the types:
₁ type colore-Spade | Coppa | Bastoni | Denari;;
2 type valore= Ace | Two | Three
Seven
Jack | Knight | King;;
3 type mazzo=Null | Carta of carta and carta={c: colore; v
: valore; mutable tl: mazzo}; ;
SEN
BOLZ
P
06004
HO HO +
Four | Five | Six |
EHI
EMI
000 000
Write a function points: mazzo -> int = <fun> The given a deck of
cards it calculates the point score of it. The scoring is as follows: Ace is
worth 1 point; Two, Three, King, Knight, Jack are each worth ; and the
Transcribed Image Text:You are given the types: ₁ type colore-Spade | Coppa | Bastoni | Denari;; 2 type valore= Ace | Two | Three Seven Jack | Knight | King;; 3 type mazzo=Null | Carta of carta and carta={c: colore; v : valore; mutable tl: mazzo}; ; SEN BOLZ P 06004 HO HO + Four | Five | Six | EHI EMI 000 000 Write a function points: mazzo -> int = <fun> The given a deck of cards it calculates the point score of it. The scoring is as follows: Ace is worth 1 point; Two, Three, King, Knight, Jack are each worth ; and the
8
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.
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); t1= x}) Null ;;
2 val generate_cards : int -> int -> mazzo = <fun>
3 # points Null ;;
: int = 0
9
5 # points (generate_cards 20 2023) ;;
6
: int = 4
#points (generate_cards 60 2024) ;;
: int = 20
#points (generate_cards 30 2020) ;;
10
: int = 9
11 # max_cards Null ;;
12
: mazzo = Null
13 # max_cards (generate_cards 50 2023) ;;
: mazzo = Carta {c = Coppa; v = Three; tl = 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
: mazzo =
Write a function max_cards: mazzo -> mazzo = <fun> that takes a
deck of cards and filters out everything except the highest cards by value
(valore) of any 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.
21
19 Carta
20
{c
Denari; v = Ace;
Carta {c = Coppa; v = Ace; tl = Carta {c =
Spade; v Ace; t1 = Null}}}
tl
Transcribed Image Text:8 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. 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); t1= x}) Null ;; 2 val generate_cards : int -> int -> mazzo = <fun> 3 # points Null ;; : int = 0 9 5 # points (generate_cards 20 2023) ;; 6 : int = 4 #points (generate_cards 60 2024) ;; : int = 20 #points (generate_cards 30 2020) ;; 10 : int = 9 11 # max_cards Null ;; 12 : mazzo = Null 13 # max_cards (generate_cards 50 2023) ;; : mazzo = Carta {c = Coppa; v = Three; tl = 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 : mazzo = Write a function max_cards: mazzo -> mazzo = <fun> that takes a deck of cards and filters out everything except the highest cards by value (valore) of any 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. 21 19 Carta 20 {c Denari; v = Ace; Carta {c = Coppa; v = Ace; tl = Carta {c = Spade; v Ace; t1 = Null}}} tl
Expert Solution
steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY