A Lindenmayer system (L-system) is a parallel rewriting system and a type of formal grammar. Some uses of L-systems include creating a visual representation of vegetation, flowers, trees, and grasses.
An L-system consists of an axiom and a set of rules.
The axiom (A) is a string that represents the starting state of the L-system.
The set of rules defines what happens to each letter in an iteration of the system.
Given the axiom, set of rules, and the number of iterations for which to run the system, you are tasked with generating a two-letter code followed by the length of the final state. The two-letter code will be the concatenation of the first letter and last letter of the final state.
DATA21.txt (DATA22.txt for the second try) will contain 10 datasets.
Each dataset begins with three terms R, T, A (1≤ R ≤ 26, 1 ≤ T ≤ 30, 1 ≤ |A| ≤ 5, the number of rules, the number of iterations, and the axiom. The next R lines each contain a character C followed by a string S ( 1≤ |S| ≤ 3) which represents a rule stating that each occurrence of C should be replaced with the string S. It is guaranteed that each letter in the system will have a corresponding rule.
For the first 4 cases, T ≤ 5.
For the first 7 cases, T ≤ 12.
For each dataset, output a concatentation of the first and last letter of the state and the length of the state after T iterations.
3 5 AC
A CAB
B CB
C ACB
4 5 AD
A AC
B ACA
C BD
D B
CB 288
AB 60
In the first dataset, the first iteration is AC > CABACB.
In the second dataset, the first two iterations are AD > ACB > ACBDACA.