6
James Bond is about to start a new mission and you are his computer scientist friend. As Tic Tac Toe is becoming more and more popular you decide that nothing would be more underhanded than a Tic Tac Toe encoder/decoder™.
For each line the decoder will follow the following steps:
Convert from 'O','X' and ' ' [space] to trinary
' ' -> 0
'O' -> 1
'X' -> 2
Convert from trinary to decimal
Convert from decimal to letter
Example: "XO "
210
21
v
The encoder will do the reverse.
As code is much more precise than words, see the reference answer below in which I give an example (very long) implementation of the problem in Python:
Your decoder should be able to decode all the messages encoded with my encoder correctly and my decoder should be able to decode all the messages encoded with your encoder.
This is code-golf, the shortest wins.
Additional informations
0 must be converted to a, the alphabet ends with a whitespace, so 26-> ' ' [whitespace]
"XXX" is the max, it translates to "222" that translates to 26.
As in Tic Tac Toe the max line lenght is 3.
X -> 2
means X should be replaced by 2Encoder/Decoder
- The encoder goes from plaintext to code.
- The decoder goes from code to plaintext.
This is a code-golf. Which means that the code with the smallest bytes is the winner. Instead, you chose the one with the largest bytes. What's wrong with you ? – Optimizer – 2014-12-20T23:17:39.273
What happens when the result of the third step in encoding is grater than 26 ? – Optimizer – 2014-12-10T19:19:55.270
@optimizer It can't be: "OOO" is the max, it translates to "222" that translates to 26. – Caridorc – 2014-12-10T19:21:47.850
Oh, we only get 3 characters at a time ? Nobody mentioned that :) – Optimizer – 2014-12-10T19:22:14.370
Yes, as in Tic Tac Toe the max line lenght is 3. – Caridorc – 2014-12-10T19:23:36.790
X -> 1 but
XO
-> 210 ? instead of 120 ? – Optimizer – 2014-12-10T19:31:43.507Also,
210
in trinary is21
in decimal, not19
. – marinus – 2014-12-10T19:32:42.817Wow acc. to his code, X -> 2. Totally unclear what he means here.. – Optimizer – 2014-12-10T19:34:09.263
X -> 2 means X should be replaced by 2 – Caridorc – 2014-12-10T19:35:49.453
1Also, should 1 mean
a
or 0 meana
? because if 0 meansa
, thenXXX
, i.e. 26 means}
– Optimizer – 2014-12-10T19:37:40.5771@Optimizer 0 means a – Caridorc – 2014-12-10T20:01:14.093
@Optimizer The alphabet ends with a whitespace, so 26-> ' ' [whitespace] – Caridorc – 2014-12-10T20:03:11.243
1You have to put all these things in the questions as the spec. Do you believe that people will read the comments for sure ? – Optimizer – 2014-12-10T20:08:29.827