- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
85 lines (75 loc) · 2.4 KB
/
Copy pathProgram.cs
File metadata and controls
85 lines (75 loc) · 2.4 KB
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
77
78
79
80
81
82
83
84
85
// Program.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingLinqFaroShuffle;
namespaceSampleLinqProject
{
classProgram
{
// Program.cs
staticvoidMain(string[]args)
{
varstartingDeck=Suits()
.SelectMany(suit =>Ranks()
.Select( rank =>new{Suit=suit,Rank=rank}))
.LogQuery("Starting Deck")
.ToArray();
// Display each card that we've generated and placed in startingDeck in the console
foreach(varcardinstartingDeck)
{
Console.WriteLine(card);
}
Console.WriteLine();
vartimes=0;
// We can re-use the shuffle variable from earlier, or you can make a new one
varshuffle=startingDeck;
do
{
// Out shuffle
/*
shuffle = shuffle.Take(26)
.LogQuery("Top Half")
.InterleaveSequenceWith(shuffle.Skip(26)
.LogQuery("Bottom Half"))
.LogQuery("Shuffle");
*/
// In shuffle
shuffle=shuffle.Skip(26).LogQuery("Bottom Half")
.InterleaveSequenceWith(shuffle.Take(26).LogQuery("Top Half"))
.LogQuery("Shuffle")
.ToArray();
foreach(varcardinshuffle)
{
Console.WriteLine(card);
}
times++;
Console.WriteLine();
}while(!startingDeck.SequenceEquals(shuffle));
Console.WriteLine(times);
}
staticIEnumerable<string>Suits()
{
yieldreturn"clubs";
yieldreturn"diamonds";
yieldreturn"hearts";
yieldreturn"spades";
}
staticIEnumerable<string>Ranks()
{
yieldreturn"two";
yieldreturn"three";
yieldreturn"four";
yieldreturn"five";
yieldreturn"six";
yieldreturn"seven";
yieldreturn"eight";
yieldreturn"nine";
yieldreturn"ten";
yieldreturn"jack";
yieldreturn"queen";
yieldreturn"king";
yieldreturn"ace";
}
}
}