Is it possible to repeat iterations of nested if statements with a new value with each separate iteration? I am trying to build 1-dimensional cellular automata (for homework, I cannot deny it), and I am completely unfamiliar with C #, as the following code will undoubtedly assure. I tried to create this program using the simplest, most basic, affordable DIY methods and put myself in a rut.
I have a string of 1 and 0 of length 8, let's say
string y;
y = "11110000";
I want to break this setting into 8 subscript sets of 3 with each set consisting of a value in y along with one value on either side of it. So, counting from 0, the 3rd set will be 110, the 7th will be 001. However, the substrings will only provide the 1st through 6th set, since I can not code them around y to my liking, so I determined the following -
y1=y.Substring(7,1)+y+y.Substring(0,1);
Using y1, I was able to get all the necessary substrings. They were mainly defined as follows:
string a0, a1, a2, a3, a4, a5, a6, a7;
a0 = y1.Substring(0, 3);
a1 = y1.Substring(1, 3);
a2 = y1.Substring(2, 3);
a3 = y1.Substring(3, 3);
a4 = y1.Substring(4, 3);
a5 = y1.Substring(5, 3);
a6 = y1.Substring(6, 3);
a7 = y1.Substring(7, 3);
The rules for the next generation of cellular automata depend on the user in this program, that is, the user can choose whether the substring is, say, 111-> 0 or 1 for all iterations. I used (very much) if the tables for each substring
{
if (a0=="000")
{
Console.Write(a);
}
else if (a0=="001")
{
Console.Write(b);
}
else if (a0 =="010")
{
Console.Write(c);
}
else if (a0 == "011")
{
Console.Write(d);
}
else if (a0 == "100")
{
Console.Write(e);
}
else if (a0 == "101")
{
Console.Write(f);
}
else if (a0 == "110")
{
Console.Write(g);
}
else if (a0 == "111")
{
Console.Write(h);
}
}
a, b, c, d, e, f, g, h int , . , , , 000 1 , a = 1. b {0,0,1}, c {0,1,0} .. , 1 ints, . y1 ( ). , !