A
substitution rule describes how to take a sequence of symbols and convert it into a different
sequence of symbols. For example, ABA → BBB, is a substitution rule which means that ABA
can be replaced with BBB. Using this rule, the sequence AABAA would be transformed into the
sequence ABBBA (the substituted symbols are in bold).
In this task, you will be given three substitution rules, a starting sequence of symbols and a final
sequence of symbols. You are to use the substitution rules to convert the starting sequence into the
final sequence, using a specified number of substitutions.
For example, if the three substitution rules were:
1. AA → AB
2. AB → BB
3. B → AA
we could convert the sequence AB into AAAB in 4 steps, by the following substitutions:
AB → BB → AAB → AAAA → AAAB,
where the symbols to be replaced are shown in bold. More specifically, from the initial sequence
AB, substitute rule 2 starting at position 1, to get the result BB. From BB, substitute rule 3, starting
at position 1, to get the result AAB. From AAB, substitute rule 3, starting at position 3, to get the
result AAAA. From AAAA, substitute rule 1, starting at position 3, to get the result AAAB, which
is the final sequence.