• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Please Help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

TFawks

Registered
Joined
Sep 15, 2008
Location
Live in CT, College in NH.
I'm worried about failing out of my Programming class, it's going so fast!

I have to make a Cellular Automata in C#. I have to be able to say how many lines to write, and it loops. I'm guessing a while loop... It prints a white box, and then on subsequent lines it prints boxes based on the last row. "To Decide the color of the square at the nth place, look at the squares in the previous row that are in the nth and (n-1) places. If those squares are the same (Both Black or Both White), then the square on the new line in the nth place will be black."

I don't even understand how to write a white box on a console window! PLEASE help me.
 
I'm worried about failing out of my Programming class, it's going so fast!

I have to make a Cellular Automata in C#. I have to be able to say how many lines to write, and it loops. I'm guessing a while loop... It prints a white box, and then on subsequent lines it prints boxes based on the last row. "To Decide the color of the square at the nth place, look at the squares in the previous row that are in the nth and (n-1) places. If those squares are the same (Both Black or Both White), then the square on the new line in the nth place will be black."

I don't even understand how to write a white box on a console window! PLEASE help me.

Well, lots of caveats:
1) I don't know stink about C#
2) Idk what a "Cellular Automata" is
3) Your description doesn't fill me with splendid knowledge :p

To display something in a console window, you use ASCII character sets. Go get this table, you will refer to it a LOT: http://www.asciitable.com

In that table, you'll notice 176, 177, 178 when printed (to the screen), will give you a nice one char sized "box" in a console window. They show both the background and some of the foreground color, in different gradients, light to darker.

For a solid color char, look at 219.

The color black is zero, and white is usually 15, although sometimes it's the same grayish as 7, only. Both black and white can be a background or a foreground, color.

If you need to draw larger "boxes", you can use these single char's, to build your boxes up, but that is more complicated than you may need.

Programming is a lot of work, and it's hard to say how long a certain program will take you to code it up. Leave yourself plenty of time, and get to work on them, asap. Don't put it off!
 
Last edited:
I'm worried about failing out of my Programming class, it's going so fast!

I have to make a Cellular Automata in C#. I have to be able to say how many lines to write, and it loops. I'm guessing a while loop... It prints a white box, and then on subsequent lines it prints boxes based on the last row. "To Decide the color of the square at the nth place, look at the squares in the previous row that are in the nth and (n-1) places. If those squares are the same (Both Black or Both White), then the square on the new line in the nth place will be black."

I don't even understand how to write a white box on a console window! PLEASE help me.

Based on that description right there, my best guess would be that you'd want a for loop, as it sounds like you're going to need a counter.

I'm off for a client meeting here in a few, so I don't have a ton of time... but I'll take another look at it later this afternoon when I get back, if you're still having troubles.
 
OK, I'm not too familiar with that problem. Never had to do it in any of my previous programming classes. Sounds like one of those wonderful ones that is simply designed to test your patience as much as your programming "skill". Here's a blog post you might find helpful. It addresses the same problem, but it makes use of threading and gui stuff. You can probably ignore those parts of it and just focus on the meat of the problem:

http://blogs.msdn.com/calvin_hsia/archive/2008/07/14/8731955.aspx
 
My Apologies. I thought that Cellular Automata was a common project, it seems I was mistaken.

We need to make Pavlov's Carpet automate in a For Loop using a Variable for the amount of lines, and using White and Black boxes, based on the formula I posted in the first post.
 
You must be a good dancer TFawks. :)

You dance around the question at hand, like a pro.

*EXACTLY* what are you stuck on? Show your work, or thoughts on solving this, and tell us precisely what you're stuck on.

My crystal ball is out for repair, and reading minds was never quite the science it should have been.

Right now it's looking like you'd prefer to have someone do the program for you - may I add that will happen when pigs fly? :D

Glad to help if I can, but never to just do your work for you.
 
Again, I thought that people knew what "Pavlov's Carpet" was.
It's a pattern based out of triangles. I'll take a screenshot of it.

THIS is my work.
Console.WriteLine("\t\t\t\tCellular Automata");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Enter the Number of Lines to Print. (Reccomended Less than 300):");
Convert.ToInt32(Console.ReadKey());

I have absolutely no idea what to do, where to start, or anything. I'm utterly confused. I'm not trying to get anyone to do the program for me. I've fallen incredibly behind. I don't understand how to set up a for loop with a variable. I don't know how to even print those white boxes on the console screen. If I could get help with both of these, I guess I could come up with something for the rest of the program.

98411945tm5.png

The triangle pattern in the console window is "Pavlov's Carpet".
 
Well, to get you started, you'd want to read in the number of lines, in this case, and do something like this:

Code:
int lineCount;

try
{
    lineCount = int.Parse(Console.ReadKey());

    for (int i = 0; i < lineCount; i++)
    {
        // do something here to write the lines to the console window
    }
}
catch (FormatException ex)
{
    // do something here to tell the user to enter a valid int
}
 
Daaang, I must be far more of a math nerd than I thought because I understand the problem in the first post just fine! :)

Cellular automata: A problem where you consider a universe, discritized into "cells" of some size. Given the universe's starting condition and rules for how the universe evolves (which define the state of a cell after a single step in time only in terms of other cells). Perhaps the most famous cellular automata is Conway's Game of Life (read this article to get an idea of what this paragraph means :))

Pavlov's Carpet: I've never heard it refered to with this name, but the screenshot looks awfully like a Sierpinski triangle (which is a triangular version of the Sierpinski carpet, itself a 2D generalization of the Cantor set).

~~~~~~~~~~~~~~~~~~~

YellowDart has the framework set up for the loop that will power the program. The "do something here to write the lines to the console window" section is where you'll do the calculation you quoted in the first post.

Since its a little difficult to have the program "look" at the line above where you're printing, I'd have an array store the white/black value of each cell. You can do your calculations directly on this array, and then print out a line based on its contents at the end.

Fleshing out YellowDart's example a little more gives us this:

Code:
int lineCount;   //Number of lines to print

bool[] lastLine; //FALSE is "black"; TRUE is "white"
bool[] thisLine;

try
{
    lineCount = int.Parse(Console.ReadKey());
    lastLine = new bool[lineCount];
    lastLine[0] = true; //Starting condition that you didn't mention...

    for (int i = 0; i < lineCount; i++)
    {
        //Perform the calculation on each cell in the array        
        thisLine = new bool[lineCount];

        for (int j = 1; j < lastLine.length; j++)
        {
            //To Decide the color of the square at the jth place,
            //look at the squares in the previous row that are in
            //the jth and (j-1) places. If those squares are the
            //same (Both Black or Both White), then the square on
            //the new line in the jth place will be black.
        }
        
        //Print the line, cell by cell
        
        //Save this line for the next iteration
    }
}
catch (FormatException ex)
{
    // do something here to tell the user to enter a valid int
}
 
JigPu said:
Daaang, I must be far more of a math nerd than I thought because I understand the problem in the first post just fine! ;)

That must be why you're green Mr JigPu. :p

I thought "Pavlov's Carpet" sounded odd... wasn't he a psychologist? Didn't seem to fit quite right, considering the nature of the problem. Now if he needed to write an algorithm to simulate Classical Conditioning, I could see the Pavlov reference. ;)
 
That must be why you're green Mr JigPu. :p

I thought "Pavlov's Carpet" sounded odd... wasn't he a psychologist? Didn't seem to fit quite right, considering the nature of the problem. Now if he needed to write an algorithm to simulate Classical Conditioning, I could see the Pavlov reference. ;)


Heh. I blame my professor for that one.

Thank you, both of you. I've got something that's starting to resemble what I'm looking for now. It's just now I need to impliment the "equasion" so to speak, which I can get done relatively easy.

Thanks again! ^^
 
Back