For all trinary numbers with length 36 (including those starting with 0’s), how many have exactly equal counts of 1’s and 2’s, or exactly one more 1 than 2?
For example:
- 00 – yes
- 01 – yes
- 02 – no
- 10 – yes
- 11 – no
- 12 – yes
- 20 – no
- 21 – yes
- 22 – no
So for all trinary numbers of length 2, 5 out of 9 possibilities match. This presumably gets smaller as the length increases. For length 3, there are 13 out of 27.
If we were dealing with binary numbers, there are a number of solutions available here but it isn’t clear to me how to generalise these to trinary numbers.
A friend of mine gave me the following answer, and he knows more math than I do. I have marked this as ‘community’ because it is not my work.
You would need to know the number of ways for every (most?) combination, not just equal 1s/2s. EG you can put together +18 and -18 to get an equal number of 1s and 2s
Solving directly seems much easier.
Do the combinatorics
Perl script to print out lines for bc, because I’m too lazy to write code that balances the multiplications and divisions nicely.