Search code examples
regexautomataternary-representation

Ternary Numbers, regex


I'm looking for some regex/automata help. I'm limited to + or the Kleene Star. Parsing through a string representing a ternary number (like binary, just 3), I need to be able to know if the result is 1-less than a multiple of 4.

So, for example 120 = 0*1+2*3+1*9 = 9+6 = 15 = 16-1 = 4(n)-1.

Even a pointer to the pattern would be really helpful!


Solution

  • You can generate a series of values to do some observation with bc in bash:

    for n in {1..40}; do v=$((4*n-1)); echo -en $v"\t"; echo "ibase=10;obase=3;$v" | bc ; done 
    
    3   10
    7   21
    11  102
    15  120
    19  201
    23  212
    27  1000
    31  1011
    ...