-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
77 lines (65 loc) · 1.8 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
/*
- There are 18 animals in total
- There will be 3 visiting schools
- School A has 6 visiting groups (the default number)
- School B has 3 visiting groups
- School C has 2 visiting groups
- For each visiting school, perform the following tasks
- Randomize the animals
- Assign the animals to the correct number of groups
- Print the school name
- Print the animal groups
*/
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[,] group = AssignGroup(groups);
Console.WriteLine(schoolName);
PrintGroup(group);
Console.WriteLine();
}
void RandomizeAnimals()
{
Random random = new Random();
for (int i = 0; i < pettingZoo.Length; i++)
{
int r = random.Next(i, pettingZoo.Length);
string temp = pettingZoo[i];
pettingZoo[i] = pettingZoo[r];
pettingZoo[r] = 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[,] group)
{
for (int i = 0; i < group.GetLength(0); i++)
{
Console.Write($"Group {i + 1}: ");
for (int j = 0; j < group.GetLength(1); j++)
{
Console.Write($"{group[i, j]} ");
}
Console.WriteLine();
}
}