-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
85 lines (75 loc) · 2.4 KB
/
Program.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
using System;
using System.Collections.Generic;
using System.Linq;
using LinqFaroShuffle;
namespace SampleLinqProject
{
class Program
{
// Program.cs
static void Main(string[] args)
{
var startingDeck = 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 (var card in startingDeck)
{
Console.WriteLine(card);
}
Console.WriteLine();
var times = 0;
// We can re-use the shuffle variable from earlier, or you can make a new one
var shuffle = 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 (var card in shuffle)
{
Console.WriteLine(card);
}
times++;
Console.WriteLine();
} while (!startingDeck.SequenceEquals(shuffle));
Console.WriteLine(times);
}
static IEnumerable<string> Suits()
{
yield return "clubs";
yield return "diamonds";
yield return "hearts";
yield return "spades";
}
static IEnumerable<string> Ranks()
{
yield return "two";
yield return "three";
yield return "four";
yield return "five";
yield return "six";
yield return "seven";
yield return "eight";
yield return "nine";
yield return "ten";
yield return "jack";
yield return "queen";
yield return "king";
yield return "ace";
}
}
}