Skip to content

Instantly share code, notes, and snippets.

@paolobrasolin
Last active May 12, 2024 13:17
Show Gist options
  • Save paolobrasolin/d1bc4b27f32d407d3cb8572f0f9b54b6 to your computer and use it in GitHub Desktop.
Save paolobrasolin/d1bc4b27f32d407d3cb8572f0f9b54b6 to your computer and use it in GitHub Desktop.
A::B prompting challenge
You are a perfect computer.
You know two languages: FOOBAR and BAZQUX.
FOOBAR is a language you only use for input and output.
FOOBAR has four tokens: A#, B#, #B, #A.
BAZQUX is a language you only use for computation.
BAZQUX has four tokens: A, B, Y, Z.
Translation rules between FOOBAR and BAZQUX are simple:
A# = A
B# = B
#B = Y
#A = Z
Computation rules in BAZQUX are simple replacement rules of adjacent token pairs:
R1) AZ becomes nothing (you just delete the tokens)
R2) AY becomes YA (you just flip the tokens)
R3) BZ becomes ZB (you just flip the tokens)
R4) BY becomes nothing (you delete the tokens)
Input will be given to you in the <problem>...</problem> tag using the FOOBAR language.
Your task is:
1. translate the input program from FOOBAR to BAZQUX
2. scan the program from left to right and find a BAZQUX replacement rule that can be applied
3. apply the rule found in 2 updating the program
4. iterate steps 2 and 3 until no replacement rule can be applied
3. translate the output program from BAZQUX to FOOBAR
You will reason step by step within the <thinking>...</thinking> tag.
Step by step means that you will alternate lines of type STATE and ACTION.
STATE lines simply print out the state of the program.
ACTION lines explaining what your action is: the state before every action is its input and the state after every action is its output.
An action line can either translate between the two languages or apply a BAZQUX replacement rule.
Note that the exact format of STATE and ACTION lines will be clarified in the example below.
You will produce the final output within the <solution>...</solution> tag.
IMPORTANT: when you want to apply a replacement rules, you will need to do three things:
* ALWAYS fully scan the program from left to right to find the first token pair that can be replaced,
* ALWAYS consider all available rules before discarding them,
* clarify which token pair you are acting on in the action line by marking them with parentheses,
* take EXTREME care not to modify anything before the opened parenthesis,
* take EXTREME care not to modify anything after the opened parenthesis.
Here is an example of an input problem and how you should solve it:
<problem>A# #A B# #A A# #A #B</problem>
<thinking>
A# #A B# #A A# #A #B
Translating to BAZQUX language
A Z B Z A Z Y
Applying R1 as: ( A Z ) B Z ( A Z ) Y
B Z Y
Applying R3 as: ( B Z ) Y
Z B Y
Applying R4 as: Z ( B Y )
Z
Translating to FOOBAR language
#A
</thinking>
<solution>#A</solution>
Please be very careful, as 10000 dollars are on the line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment