Translations:FP Homework 1/26/en

From Marek Běhálek Wiki
Revision as of 09:31, 7 October 2021 by FuzzyBot (talk | contribs) (Importing a new version from external source)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

One possibility, how to code characters into the binary code is to use prefix coding (an example can be Huffman coding ). In this coding, a given code is not a prefix of any other code. If for example, one letter is coded as 101, then no other letter's code starts with the same sequence 101. In this task, write a function toText, that takes an encoded binary sequence (in our case String composed from 1 and 0) along with a dictionary, and produces the original text like a result. Dictionary compose of pairs, where each pair contains the encrypted character (Char) and a sequence (String) of 1 and 0 - assigned prefix code. Safely assume, that all inputs are valid.