Quaternary Sequence Generation

44 Views Asked by At

How can a quaternary sequence be generated without converting decimal numbers to quaternary. For example, I need to generate at n = 2 , 4^n = 16 combinations, enter image description here.For large n, a program that converts a decimal number to a quaternary runs for a very long time.Is there a more optimal algorithm for generating such a sequence? Thanks for the answer.

1

There are 1 best solutions below

0
On

$4^n$ is $100\dots$ in quaternary. While, $4^n-1$ is $333\dots$ (one digit less than the $100\dots$). Your table seems to list numbers from $0$ to $4^n-1$. You could generate a lexicografic (dictionary) list starting with $000\dots$ and ending $333\dots$
For example when $n=1$ then we have $0,1,2,3$.
When $n=2$ then $00,01,02,03,10,11,12,13,20,21,22,23,30,31,32,33$.
When $n=3$ then we get $000,001,002,003,010,011,\dots,323,330,331,332,333$.