Cody

# Problem 185. Data decompression

Solution 3434153

Submitted on 27 Oct 2020 by Jens Kjærgaard Boldsen
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   Pass
alphabet = 'al'; table = {'1','010'}; compressed = [93,85,127]; assert(isequal(decode(compressed,table,alphabet),'laaalalalaaaaaaa'))

decompressed = 'laaalalalaaaaaaa'

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

decompressed = 'hellohellooo'

3   Pass
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. '))

decompressed = 'It is not worth the bother of killing yourself, since you always kill yourself too late. '

4   Pass
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)) ))

decompressed = 'uhhhuhuhuhhhhhhhuhhhuhuhuhhhhhhhuhhhuhuhuhhhhhhh'

5   Pass
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)));

decompressed = 'nxtqjwbyrunlvnvfaaxrmpulrfeymstokypzaxsyen'

### Community Treasure Hunt

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

Start Hunting!