-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
62 lines (53 loc) · 1.45 KB
/
Program.cs
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
using System;
string[] pettingZoo =
{
"alpacas", "capybaras", "chickens", "ducks", "emus", "geese",
"goats", "iguanas", "kangaroos", "lemurs", "llamas", "macaws",
"ostriches", "pigs", "ponies", "rabbits", "sheep", "tortoises",
};
PlanSchoolVisit("School A");
PlanSchoolVisit("School B", 3);
PlanSchoolVisit("School C", 2);
void PlanSchoolVisit(string schoolName, int groups = 6)
{
RandomizeAnimals();
string[,] group1 = AssignGroup(groups);
Console.WriteLine(schoolName);
PrintGroup(group1);
}
void RandomizeAnimals()
{
Random random = new Random();
for (int i = 0; i < pettingZoo.Length; i++)
{
int r = random.Next(i, pettingZoo.Length);
string temp = pettingZoo[r];
pettingZoo[r] = pettingZoo[i];
pettingZoo[i] = temp;
}
}
string[,] AssignGroup(int groups = 6)
{
string[,] result = new string[groups, pettingZoo.Length / groups];
int start = 0;
for (int i = 0; i < groups; i++)
{
for (int j = 0; j < result.GetLength(1); j++)
{
result[i, j] = pettingZoo[start++];
}
}
return result;
}
void PrintGroup(string[,] groups)
{
for (int i = 0; i < groups.GetLength(0); i++)
{
Console.Write($"Group {i + 1}: ");
for (int j = 0; j < groups.GetLength(1); j++)
{
Console.Write($"{groups[i, j]} ");
}
Console.WriteLine();
}
}