Cody

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

Solution 3375923

Submitted on 25 Oct 2020 by Nikolaos Nikolaou
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))

s = '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.'

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

s = 'MATLAB is awesome!'

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

s = 'foo bar baz qux'

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

s = 'L.LdnSG'iyo!rU:ZWf'jz:uLxeDjhZFg?gjuJAtncbdMyFype'XomvJMRgMtEbtZm?YJK!FBv.? wJMLBRC:p;PJzHYuMTbPB:p' s = 'PC?y VzTrDY?tXXNE!uSDcz;;sqY!dtKRMEG!:iRAzY'beTZGbTHXFhaxdjKpt L;aRnSJLam.BRHkS:pdWDjOMNogxtmjB::wsg' s = 'Beei'snbHVae.VX rjVrlgPs t'?cAj;LP: C?whkmV;H'Pjw:C;KyZO 'jO?Tl?SJHBE'.?utDorur;stHfIIkkLG .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NQhZhHVie;b'mnkm'!BCh?JypVXiirCbzS?Oo En?!U!BswK;Cl'm'ChnG;C;siNAJw:M?Kx?gIqej.MhvkT:kdR X.jxad!.S' s = 'PuoAT'O:Unqv'IXBwmlJIe?JhcYd;dfEe o;! L!X xEj l?ZPwMOrqrg.?d:Y'XrZd .LgBDHm;X?hLplA!QiHcHtAN:?W'!sn' s = 'kp !RscTJop:lxikFMn' GzseZWZZIgYiNos lPKa:Rs!hr;wLAmpYwdbGuJNbNTQJoMhiJM...

### Community Treasure Hunt

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

Start Hunting!