3 ms·
I read the article title, glossed over the article, and thought it would be a fun problem to solve. The scheme I came up with assumes a representation of terna
by RiverCrochet 2y ago
I read the article title, glossed over the article, and thought it would be a fun problem to solve.
The scheme I came up with assumes a representation of ternary numbers as bit pairs 00, 01, and 10 in a byte. Since there are 4 bit pairs in a byte, we can represent 4 ternary digits t0, t1, t2, and t3 no issue.
Since 11 doesn't map to a valid ternary digit, I had an idea that the presence and position of 11 bit pairs could change how the other bit pairs are interpreted - so that's where t4 comes from. If there are no 11 bit pairs, t4 is 0.
Working the combinations I just needed 3 cases - 0, 1, and 2 11-bit pairs in the byte. The byte values with 3 11-bit pairs didn't have to be used.
The 4 11-bit pair, all ones, I decided could be used to signal end of stream.