Problem 42370. The Python Challenge, Level 1: Decode strings

Solution 1690727

Submitted on 11 Dec 2018 by Rose Wright
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
str = 'G fmnc wms bgbl''r rpylqjyrc gr zw fylb. Rfyr''q ufyr amknsrcpq ypc dmp. Bmgle gr zw fylb gq glcddgagclr ylb rfyr''q ufw rfgq rcvr gq qm jmle. Sqgle pcecvn gq pcamkkclbcb.'; s_correct = 'I hope you didn''t translate it by hand. That''s what computers are for. Doing it by hand is inefficient and that''s why this text is so long. Using regexp is recommended.'; assert(isequal(strdecode(str),s_correct))

2   Pass
str = 'KYRJYZ gq yucqmkc!'; s_correct = 'MATLAB is awesome!'; assert(isequal(strdecode(str),s_correct))

3   Pass
str = 'dmm zyp zyx osv'; s_correct = 'foo bar baz qux'; assert(isequal(strdecode(str),s_correct))

4   Pass
p = ' .?!'';:'; for ii=1:100 str = ''; for jj=1:100 r = rand; if r<0.4 str(jj) = randi([65 90]); elseif r<0.8 str(jj) = randi([97 122]); else str(jj) = p(randi(7)); end end s_correct = regexprep(strdecode(str),'([C-Zc-z])*([ABab])*','${char($1-2)}${char($2+24)}'); assert(isequal(str,s_correct)) end

Suggested Problems

More from this Author44

Community Treasure Hunt

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

Start Hunting!