One of many unique features of the Malbolge programming language is its highly unintuitive OP
operator, referred to only as "op" in the documentation and source code but popularly known as the "crazy" operator. As described by Ben Olmstead, the creator of the language, in its documentation: "don't look for pattern, it's not there."
op is a "tritwise" operator -- it operates on corresponding ternary digits of its two arguments. For each trit (ternary bit), the result of op is given by the following lookup table:
a
op(a,b) 0 1 2
+-------
0 | 1 0 0
b 1 | 1 0 2
2 | 2 2 1
For example, to calculate op(12345, 54321)
, first write out both numbers in ternary and then look up each pair of trits in the table:
0121221020 (12345_3)
op 2202111220 (54321_3)
--------------
2202220211 (54616_3)
The last important point is that all values in Malbolge are 10 trits wide, so input values should be padded with zeroes to a width of 10. (For instance, op(0, 0)
is 1111111111
in ternary.)
Your task is to take two integers 0 ≤ a
, b
< 59049 as input, and output the integer value of op(a,b)
.
Test cases (in the format a b op(a,b)
):
0 0 29524
1 2 29525
59048 5 7
36905 2214 0
11355 1131 20650
12345 54321 54616
Here is a reference implementation (copied directly from the Malbolge source code).
54616_3
doesn't mean "this other thing is the decimal number 54616, but represented as base three". It means "Read54616
as base 3". Which, of course, you can't do (there are digits that Valve can't count to in there). It'd still probably be just as clear if you got rid of the_3
entirely, and more accurate. \$\endgroup\$