The MU puzzle is a puzzle in which you find out whether you can turn MI
into MU
given the following operations:
If your string ends in
I
, you may add aU
to the end. (e.g.MI -> MIU
)If your string begins with
M
, you may append a copy of the part afterM
to the string.
(e.g.MII -> MIIII
)If your string contains three consecutive
I
's, you may change them into aU
.
(e.g.MIII -> MU
)If your string contains two consecutive
U
's, you may delete them. (e.g.MUUU -> MU
).
Your task is to build a program that determines whether this is doable for any start and finish strings.
Your program will take two strings as input. Each string will consist of the following:
one
M
.a string of up to twenty-nine
I
's andU
's.
Your program will then return true
(or your programming language's representation thereof/YPLRT) if the second string is reachable from the first string, and false
(or YPLRT) if it is not.
Example inputs and outputs:
MI MII
true
MI MU
false
MIIIIU MI
true
The shortest code in any language to do this wins.
MI
are exactly theM(I|U)*
where the number ofI
isn't a multiple of 3. And such a direct check surely makes for shorter code. Also, I don't know of an a-priori bound on the lengths of strings required for intermediate steps, so direct search might be simply impractical. \$\endgroup\$MI
of a given reachable string. \$\endgroup\$IM
is supplied orMUMMI
? \$\endgroup\$