-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·53 lines (42 loc) · 1.48 KB
/
main.cpp
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
// ZyLab - Bitwise ops - 1D Cellular Automata
// Original - Loceff, Updates, Edits, Annotations: &
//
// This main method is for your benefit. It will not be tested. But if you use it as
// an example to run your own tests, the likelihood of your Automaton code passing
// my tests may be higher.
// - &
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#include "Automaton.h"
// getRows will rewind aut and return its first n generations as a string
// in which successive generations are separated by "\n". Within the strings
// 1 is represented by * and 0 by space.
string getRows(Automaton& aut, int n) {
char charFor0 = ' ', charFor1 = '*';
stringstream ss;
aut.resetToFirstGen(); // rewind
while (--n >= 0) {
ss << aut.toStringCurrentGen(charFor0, charFor1) << "\n";
aut.propagateNewGen();
}
return ss.str();
}
int main()
{
int rule;
string userInput;
cout << "Enter Rule (" << Automaton::MIN_RULE << " - " << Automaton::MAX_RULE << "): ";
getline(cin, userInput);
istringstream(userInput) >> rule;
if (rule < Automaton::MIN_RULE || rule > Automaton::MAX_RULE) {
cerr << "Sorry. That was an invalid rule number." <<endl;
exit(1);
}
// Make the automaton and print its first 100 rows on cout
Automaton aut(rule);
cout << getRows(aut, 100) << endl;
// TODO - run other tests to cover corner cases, limit checking, etc.
/* Type your code here */
}