-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday6.cs
98 lines (84 loc) · 3.26 KB
/
day6.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
//Create list of all fish starting in the list
List<int> listOfFish = new List<int>()
{
1,4,1,1,1,1,5,1,1,5,1,4,2,5,1,2,3,1,1,1,1,5,4,2,1,1,3,1,1,1,1,1,1,1,2,1,1,1,1,1,5,1,1,1,1,1,1,1,1,1,4,1,1,1,1,5,1,4,1,1,4,1,1,1,1,4,1,1,5,5,1,1,1,4,1,1,1,1,1,3,2,1,1,1,1,1,2,3,1,1,2,1,1,1,3,1,1,1,2,1,2,1,1,2,1,1,3,1,1,1,3,3,5,1,4,1,1,5,1,1,4,1,5,3,3,5,1,1,1,4,1,1,1,1,1,1,5,5,1,1,4,1,2,1,1,1,1,2,2,2,1,1,2,2,4,1,1,1,1,3,1,2,3,4,1,1,1,4,4,1,1,1,1,1,1,1,4,2,5,2,1,1,4,1,1,5,1,1,5,1,5,5,1,3,5,1,1,5,1,1,2,2,1,1,1,1,1,1,1,4,3,1,1,4,1,4,1,1,1,1,4,1,4,4,4,3,1,1,3,2,1,1,1,1,1,1,1,4,1,3,1,1,1,1,1,1,1,5,2,4,2,1,4,4,1,5,1,1,3,1,3,1,1,1,1,1,4,2,3,2,1,1,2,1,5,2,1,1,4,1,4,1,1,1,4,4,1,1,1,1,1,1,4,1,1,1,2,1,1,2
};
//User chooses how many days to run the experiment
Console.Write("Choose how many days to run the fish experiment: ");
int numberOfDays = 0;
bool success = false;
List<int> listOfFishTemp = new List<int>()
{
};
while (success != true)
{
success = Int32.TryParse(Console.ReadLine(), out numberOfDays);
if (success)
{
//Runs the experiement as many days as chosen
for (int j = 0; j < numberOfDays; j++)
{
/*Write out the whole list of fish values
foreach (int i in listOfFish)
{
Console.Write(i);
Console.Write(",");
}
*/
//Count all 0 = Zeros
int Zeros = (from x in listOfFish where x < 1 select x).Count();
//Remove all 0
listOfFish.RemoveAll(x => x < 1);
//Adds new fish for each Zeros
for(int i = 0;i < Zeros; i++)
{
listOfFishTemp.Add(7);
listOfFishTemp.Add(9);
}
//Merges the two lists
listOfFish.AddRange(listOfFishTemp);
//Clear listOfFishTemp
listOfFishTemp.Clear();
//Adds new fish (slow?)
/*for (int i = 0; i < Zeros; i++)
{
//Add Zeroes amount of 6's to the list as replacement of the 0's
listOfFish.Add(7);
//add Zeroes amount of 8's to the List
listOfFish.Add(9);
}
*/
//Count the number of elements in the fish list
int numberOfFish = listOfFish.Count;
//Lower all int's in listOfFish with 1
for (int i = 0; i < numberOfFish; i++)
{
listOfFish[i] = listOfFish[i] - 1;
}
Console.WriteLine(j + " number of days has passed.");
Console.WriteLine("There are now " + listOfFish.Count + " number of fish and counting...");
}
}
else
{
Console.WriteLine("Error: Write a number only");
Console.Write("Choose how many days to run the fish experiment: ");
}
}
//Outputs the number of fish in the end
Console.WriteLine(Environment.NewLine + Environment.NewLine + "There are " + listOfFish.Count + " total fish alive after " + numberOfDays + " days.");
Console.ReadKey();
}
}
}