Cody

Problem 185. Data decompression

Solution 3926203

Submitted on 30 Nov 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Fail
alphabet = 'al'; table = {'1','010'}; compressed = [93,85,127]; assert(isequal(decode(compressed,table,alphabet),'laaalalalaaaaaaa'))

Error using dec2bin Too many input arguments. Error in decode (line 2) dec = dec2bin(compressed,8,'left-msb'); Error in Test1 (line 4) assert(isequal(decode(compressed,table,alphabet),'laaalalalaaaaaaa'))

2   Fail
alphabet = 'ehlo'; table = {'00','01','10','11'}; compressed = uint8([74 210 191]); assert(isequal(decode(compressed,table,alphabet),'hellohellooo'))

Error using dec2bin Too many input arguments. Error in decode (line 2) dec = dec2bin(compressed,8,'left-msb'); Error in Test2 (line 4) assert(isequal(decode(compressed,table,alphabet),'hellohellooo'))

3   Fail
alphabet = ',.kcgIblowaisnufhe try'; table = {'000000','000001','00001','000100','000101','000110','000111','001','010','01100','01101','0111','1000','10010','10011','10100','10101','1011','110','1110','11110','11111'}; compressed = uint8([27 179 198 146 236 197 238 174 234 222 29 117 111 217 83 5 201 121 11 190 167 232 179 64 52 60 132 189 245 60 210 198 254 48 92 157 245 63 69 154 110 75 22 245 131 182]); assert(isequal(decode(compressed,table,alphabet),'It is not worth the bother of killing yourself, since you always kill yourself too late. '))

Error using dec2bin Too many input arguments. Error in decode (line 2) dec = dec2bin(compressed,8,'left-msb'); Error in Test3 (line 4) assert(isequal(decode(compressed,table,alphabet),'It is not worth the bother of killing yourself, since you always kill yourself too late. '))

4   Fail
alphabet = char(randi(13)+96); alphabet=[alphabet alphabet+randi(13)]; table = {'1','010'}; n=randi(5)+2; compressed = repmat([93,85,127],1,n); assert(isequal(decode(compressed,table,alphabet),regexprep(regexprep(repmat('laaalalalaaaaaaa',1,n),'l',alphabet(2)),'a',alphabet(1)) ))

Error using dec2bin Too many input arguments. Error in decode (line 2) dec = dec2bin(compressed,8,'left-msb'); Error in Test4 (line 5) assert(isequal(decode(compressed,table,alphabet),regexprep(regexprep(repmat('laaalalalaaaaaaa',1,n),'l',alphabet(2)),'a',alphabet(1)) ))

5   Fail
compressed = char(randi(26,1,42)+96); alphabet = unique(compressed); compressed = uint8(compressed); table = cellstr(dec2bin(alphabet,8)); assert(isequal(decode(compressed,table,alphabet), char(compressed)));

Error using dec2bin Too many input arguments. Error in decode (line 2) dec = dec2bin(compressed,8,'left-msb'); Error in Test5 (line 5) assert(isequal(decode(compressed,table,alphabet), char(compressed)));

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!