I am trying to write some kind of demonstration for coding algorithm (for prefix codes).
I have an Association that contains lists of bits (0s and 1s):
<|{"1"} -> "a", {"0", "1"} -> "b", {"0", "0"} -> "c"|>
And a list that represents a coded string (which in our example aabc
):
{1,1,0,1,0,0}
And Im trying to write a code that searches for a match between a prefix (of any length) from my coded string with a key in the association (without loops).
If I would use a loop I would try to find a prefix in the coded string in increasing length (first look for a match in length 1, then in 2 and so on..).
For now, my goal is to find a match, remove it from the list, and find the next matching. In case I am going wrong with this idea (in the matter of efficiency), I would thank you if you suggest me better ideas.
I have tried to search online and in the forum but without any success.
Any tip will be appreciated !
Thank you