-
Notifications
You must be signed in to change notification settings - Fork 1
/
Chapter1.tex
84 lines (73 loc) · 3.51 KB
/
Chapter1.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
\newpage
%----------------------------------------------------------------------------------------------------
\section{We have a problem...}
%----------------------------------------------------------------------------------------------------
\vspace{10cm}
\hrule
\lhQ What is this : \il!"8♥"!?
\lhA A \il!String!.
\lhN Yes. What does it represent?
\lhA An eight of hearts, or \hearts8.
\lhN What does \il!"7♣__6♦__9♠"! represent?
\lhA Some others cards: \clubs7, \diamonds6, and \spades9.
\lhN Right. And what does \il!"A♥__K__♥Q♥__J♥__T♥"! represent?
\lhA It represents victory: it's a royal flush.
\lhN What is the best we can do with the following: \\
\diamonds4 \diamonds2 \spades K \diamonds K \diamonds9 \clubs3 \diamonds6?
\lhA A flush.
\lhN And with \clubs9 \hearts A \spades K \diamonds K \diamonds9 \clubs3 \diamonds6?
\lhA Two pairs.
\lhN Correct. And with \clubs A \clubs Q \spades K \diamonds K \diamonds9 \clubs3?
\lhA Nothing, because there are less than seven cards.
\lhN And with \hearts9 \spades5?
\lhA Nothing, for the same reason.
\lhN That's right. \\
What about \clubs K \spades9 \spades K \diamonds K \diamonds9 \clubs3 \diamonds6?
\lhA It's a full house. Say, why are you showing me all these cards?
\lhN Because we have a problem, and I wanted to be sure you know the basics about \emph{Poker}.
\lhA Show me what the problem is.
\lhN We have to write a program wich, given this input:
\begin{alltt}
\clubs{K} \spades{9} \spades{K} \diamonds{K} \diamonds{9} \clubs{3} \diamonds{6}
\clubs{9} \hearts{A} \spades{K} \diamonds{K} \diamonds{9} \clubs{3} \diamonds{6}
\clubs{A} \clubs{Q} \spades{K} \diamonds{K} \diamonds{9} \clubs{3}
\hearts{9} \spades{5}
\diamonds{4} \diamonds{2} \spades{K} \diamonds{K} \diamonds{9} \clubs{3} \diamonds{6}
\spades{7} \spades{T} \spades{K} \diamonds{K} \diamonds{9}
\end{alltt}
\lhA These are the cards of some players in a game of \emph{Texas Hold'em}. Right?
\lhN -- right -- ..would output this:
\begin{alltt}
\clubs{K} \spades{9} \spades{K} \diamonds{K} \diamonds{9} \clubs{3} \diamonds{6} Full House (winner)
\clubs{9} \hearts{A} \spades{K} \diamonds{K} \diamonds{9} \clubs{3} \diamonds{6} Two Pair
\clubs{A} \clubs{Q} \spades{K} \diamonds{K} \diamonds{9} \clubs{3}
\hearts{9} \spades{5}
\diamonds{4} \diamonds{2} \spades{K} \diamonds{K} \diamonds{9} \clubs{3} \diamonds{6} Flush
\spades{7} \spades{T} \spades{K} \diamonds{K} \diamonds{9}
\end{alltt}
\lhA I see.
\lhN What do you see?
\lhA Some lines are just left as they are. \\
Some lines are marked with the ranking of the best possible hand given the cards on the line.\\
The line with the best ranking is marked as the winner.
\lhN Do you think we can solve the problem?
\lhA Yes, provided we have the good tools.
\lhN What is the value of: \il!filter even [4,8,0,7]!?
\lhA \il![4,8,0]!
\lhN What is the value of: \il!subsequences "abc"!?
\lhA \il!["","a","b","ab","c","ac","bc","abc"]!
\lhN And of the expression: \il!maximum [4,8,0,7]!?
\lhA \il!8!
\lhN What about: \il!zip [3,5,2] "abc"!?
\lhA \il![(3,'a'),(5,'b'),(2,'c')]!
\lhN and the expression: \il!zipWith (*)__ [3,5,2] [4,9,7]!?
\lhA \il![12, 45, 14]!
\lhN What is the value of: \\ \il!words "time flies like an arrow"!?
\lhA \il!["time","flies","like","an","arrow"]!
\lhN What is the value of: \il!compare "time"__"arrow"!?
\lhA \il!GT!, because \il!"time" > "arrow"!
\lhN What is the value of:\\ \il!comparing length "time"__"arrow"!?
\lhA \il!LT!, because \il!(length "time")__< (length "arrow)"!
\lhN Do you want to solve the problem?
\lhA Let's make some tea first.
\lhend