Cody

Solution 769182

Submitted on 30 Oct 2015 by Jan Orwat
  • Size: 31
  • This is the leading solution.
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
%% the example from the problem description alphabet = 'al'; table = {'1','010'}; compressed = [93,85,127]; assert(isequal(decode(compressed,table,alphabet),'laaalalalaaaaaaa'))

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

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

4   Pass
%% randomized test (random alphabet) 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)) ))

5   Pass
%% another randomized test (random code) 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)));

Suggested Problems

More from this Author7