Skip to content

Instantly share code, notes, and snippets.

@IronChariot
Created April 10, 2024 19:34
Show Gist options
  • Save IronChariot/ce6e275867201a1e56019a5e2f1f779b to your computer and use it in GitHub Desktop.
Save IronChariot/ce6e275867201a1e56019a5e2f1f779b to your computer and use it in GitHub Desktop.
The A::B system uses 4 tokens: 'A#', '#A', 'B#', '#B'.
The user will give a set of such tokens within the <problem></problem> tags. You should begin by transforming the tokens following these rules:
A# becomes Apple
#A becomes Orange
B# becomes Pear
#B becomes Banana
This will produce a set 'problem' within the fruit system, which you should state in its entirety.
A program in this fruit system is a sequence of tokens. Example:
Banana Orange Apple Banana Orange Orange Pear Apple Apple Apple Apple Apple
To compute a program, we must rewrite neighbouring tokens, using the rules:
Rule 1: Apple Orange becomes nothing
Rule 2: Apple Banana becomes Banana Apple
Rule 3: Pear Orange becomes Orange Pear
Rule 4: Pear Banana becomes nothing
In other words, whenever two neighbouring tokens match one of the above rules, they must be rewritten according to the corresponding rule.
Compute the program (using as many iterations as necessary). Do this by following these steps for each iteration:
1) Explicitly state each pair of tokens in the entire program string one at a time, always starting at the beginning of the string as currently evaluated, from left to right. For each pair of token, state whether or not it matches any of the rules. When you find the first pair of tokens which does match a rule, be sure to quote the rule in full. You are not allowed to declare that there are no more pairs to be processed unless you have explicitly stated all the pairs in the final prgram string.
2) Separate the initial program into three sections: the tokens which come before the token pair you chose (which will remain unchanged), the token pair to be dealt with in this step which matches one of the four rules, and the tokens located after the token pair to be evaluated (which will remain unchanged).
3) Deal with the pair of tokens according to the appropriate rule.
4) Put the three sections back together (or the two remaining sections, if the rule eliminated the token pair making up the middle section).
For example, the first example shown above can be solved with the following iterations:
Iteration 1:
1) The current program is: Banana Orange Apple Banana Orange Orange Pear Apple Apple Apple Apple Apple
Pair 1: Banana Orange (no rule match)
Pair 2: Orange Apple (no rule match)
Pair 3: Apple Banana (matches rule 2, "Apple Banana becomes Banana Apple")
2) The program can be written as three sections: Banana Orange | Apple Banana | Orange Orange Pear Apple Apple Apple Apple Apple
3) Dealing with the token pair makes them go from Apple Banana to Banana Apple.
4) Putting everything back together we get: Banana Orange Banana Apple Orange Orange Pear Apple Apple Apple Apple Apple
Iteration 2:
1) The current program is: Banana Orange Banana Apple Orange Orange Pear Apple Apple Apple Apple Apple
Pair 1: Banana Orange (no rule match)
Pair 2: Orange Banana (no rule match)
Pair 3: Banana Apple (no rule match)
Pair 4: Apple Orange (matches rule 1, "Apple Orange becomes nothing")
2) The program can be written as three sections: Banana Orange Banana | Apple Orange | Orange Pear Apple Apple Apple Apple Apple
3) Dealing with the token pair makes them go from Apple Orange to nothing.
4) Putting everything back together we get: Banana Orange Banana Orange Pear Apple Apple Apple Apple Apple
Iteration 3:
1) The current program is: Banana Orange Banana Orange Pear Apple Apple Apple Apple Apple
Pair 1: Banana Orange (no rule match)
Pair 2: Orange Banana (no rule match)
Pair 3: Banana Orange (no rule match)
Pair 4: Orange Pear (no rule match)
Pair 5: Pear Apple (no rule match)
Pair 6: Apple Apple (no rule match)
Pair 7: Apple Apple (no rule match)
Pair 8: Apple Apple (no rule match)
Pair 9: Apple Apple (no rule match)
There are no pairs of tokens which match a rule, so we are done. The final fruit system solution is Banana Orange Banana Orange Pear Apple Apple Apple Apple Apple
After all iterations have been performed and no more changes can be made, transform each fruit system token into a A::B system token, as before:
Apple becomes A#
Orange becomes #A
Pear becomes B#
Banana becomes #B
Put the final solution (in the A::B system format) within some <solution></solution> tags at the end of your solution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment