Let's define a simple language that operates on a single 8-bit value.
It defines three bitwise operations (code explanation assumes 8-bit value
variable):
!
Negate the least significant bit (value ^= 1
)<
Wrapping left-shift (value = value << 1 | value >> 7
)>
wrapping right-shift (value = value >> 1 | value << 7
)
Input:
Two 8-bit numbers, a and b. As they are 8-bit, you can alternatively take them as characters.
Output:
The shortest way to get from a to b, with the three operations defined above.
You can return a string or an array of characters, or define a constant, distinct values for each operation and return an array of those (yes, you could also say <
means >
and >
means <
), but please explain your output format in your answer.
If there are multiple, equally long ways, you can output any or all of them.
Rules:
- You can submit a program or function
- Standard loopholes apply
- The submission with fewest bytes in each language wins (no answer will be accepted)
Solutions without brute-forcing (or at least not only brute-forcing) might get my upvote.
Test cases:
12, 13 => '!'
1, 2 => '<'
254, 253 => '<'
5, 5 => ''
98, 226 -> '<!>'
64, 154 -> '!>!>>>!>'
177, 164 -> '!>>!>>>!'
109, 11 -> '>>!>!>>'
126, 92 -> '!>!>!>!<' or '!>!>>!<!'
26, 85 -> '<!<<!<!<' or '<!<<!<!>' or '<!<<<!>!'
123, 241 -> '!>!<<!' or '>!<!<!'
236, 50 -> '<<!<!>' or '<<<!>!'
59, 246 -> '<<!>'
132, 95 -> '!<<!<!<!'
74, 53 -> '!>>>!>!'
171, 127 -> '<<!<<!<'
109, 141 -> '!>>>'
185, 92 -> '!>'
166, 201 -> '!<!>>>' or '<!>!>>'
77, 155 -> '<!'
124, 181 -> '!<<<<!>>' or '!>>>>!>>'
108, 85 -> '!<<<!<!<!<' or '!<<<!<!<!>' or '!<<<!<<!>!' or '!>>>!>!>!<' or '!>>>!>!>!>' or '!>>>!>>!<!'
185, 144 -> '<!<<!<!'
70, 179 -> '<<<!<!>' or '<<<<!>!' or '>>>>!>!'
Here is a program to generate a few more.