#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
class LSystem {
public:
LSystem(const std::string& axiom, const std::unordered_map<char, std::string>& rules)
: currentString(axiom), productionRules(rules) {}
void generate(int iterations) {
for (int i = 0; i < iterations; ++i) {
std::string nextString;
for (char ch : currentString) {
if (productionRules.find(ch) != productionRules.end()) {
nextString += productionRules.at(ch);
} else {
nextString += ch;
}
}
currentString = nextString;
}
}
void display() const {
std::cout << "L-System string: " << currentString << "\n";
}
private:
std::string currentString;
std::unordered_map<char, std::string> productionRules;
};
int main() {
// Define the axiom and production rules for the L-System
std::string axiom = "F";
std::unordered_map<char, std::string> rules = {
{'F', "F+F-F-F+F"}
};
// Create an LSystem object
LSystem lSystem(axiom, rules);
// Generate the L-System string for a number of iterations
int iterations = 4;
lSystem.generate(iterations);
// Display the generated L-System string
lSystem.display();
return 0;
}