Cody

# Problem 44351. Code breaker, Part I: Operation Phoenix

Solution 1937590

Submitted on 16 Sep 2019
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
% This test suite can be updated if inappropriate 'hacks' % are discovered in any submitted solutions, % so your score/size may therefore change over time.

2   Fail
x = 'Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz & ftdbqf.'; s_correct.shift = 1; s_correct.message = 'Cancel Operation Phoenix immediately & escape.'; s = decode(x); assert( isequal(s.shift, s_correct.shift) ) assert( isequal(s.message, s_correct.message) ) assert( isequal(class(s.shift), 'uint8') ) assert( isequal(class(s.message), 'char') )

s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.'

Assertion failed.

3   Fail
x = 'Vwlyhapvu Wovlupe ilnpuz Ablzkhf! Vwlyhapvu Wovlupe pz vby avw wypvypaf.'; s_correct.shift = 7; s_correct.message = 'Operation Phoenix begins Tuesday! Operation Phoenix is our top priority.'; s = decode(x); assert( isequal(s.shift, s_correct.shift) ) assert( isequal(s.message, s_correct.message) ) assert( isequal(class(s.shift), 'uint8') ) assert( isequal(class(s.message), 'char') )

s = struct with fields: shift: 8 message: 'OperaZion Phoeni^ begins Z[esda_! OperaZion Phoeni^ is o[r Zop prioriZ_.' s = struct with fields: shift: 8 message: 'OperaZion Phoeni^ begins Z[esda_! OperaZion Phoeni^ is o[r Zop prioriZ_.'

Assertion failed.

4   Fail
x = 'Eatpht cdit iwpi iwt ephhldgs wph qttc rwpcvts ugdb "Fxeudyn" id "Dvcsbwl". Diwtglxht Detgpixdc Ewdtcxm xh egdrttsxcv prrdgsxcv id eapc.'; s_correct.shift = 15; s_correct.message = 'Please note that the password has been changed from "Qipfojy" to "Ogndmhw". Otherwise Operation Phoenix is proceeding according to plan.'; s = decode(x); assert( isequal(s.shift, s_correct.shift) ) assert( isequal(s.message, s_correct.message) ) assert( isequal(class(s.shift), 'uint8') ) assert( isequal(class(s.message), 'char') )

s = struct with fields: shift: 16 message: 'VReaYe TUZe ZhaZ Zhe VaYY]UXd haY beeT chaTged fXUS "WiVfUj_" ZU "UgTdSh]". UZheX]iYe UVeXaZiUT VhUeTi^ iY VXUceediTg accUXdiTg ZU VRaT.' s = struct with fields: shift: 16 message: 'VReaYe TUZe ZhaZ Zhe VaYY]UXd haY beeT chaTged fXUS "WiVfUj_" ZU "UgTdSh]". UZheX]iYe UVeXaZiUT VhUeTi^ iY VXUceediTg accUXdiTg ZU VRaT.'

Assertion failed.

5   Fail
x = 'Mncpyrgml Nfmclgv qryprcb rfpcc bywq yem. Yjj ncpqmllcj ypc rm pckygl ml bsrw slrgj Mncpyrgml Nfmclgv gq amknjcrcb.'; s_correct.shift = 24; s_correct.message = 'Operation Phoenix started three days ago. All personnel are to remain on duty until Operation Phoenix is completed.'; s = decode(x); assert( isequal(s.shift, s_correct.shift) ) assert( isequal(s.message, s_correct.message) ) assert( isequal(class(s.shift), 'uint8') ) assert( isequal(class(s.message), 'char') )

s = struct with fields: shift: 25 message: 'UVKXaZOUT VNUKTO^ YZaXZKJ ZNXKK Ja_Y aMU. ARR VKXYUTTKR aXK ZU XKSaOT UT J[Z_ [TZOR UVKXaZOUT VNUKTO^ OY IUSVRKZKJ.' s = struct with fields: shift: 25 message: 'UVKXaZOUT VNUKTO^ YZaXZKJ ZNXKK Ja_Y aMU. ARR VKXYUTTKR aXK ZU XKSaOT UT J[Z_ [TZOR UVKXaZOUT VNUKTO^ OY IUSVRKZKJ.'

Assertion failed.

6   Fail
% Acknowledgements % Portions of this timing test code were inspired by: % (1) Problem 937. "Rubik's Mini Cube: Solve Randomized Cube in 11 Moves or Less; Score is by Time (msec)" by Richard Zapor. % (2) Problem 2733. "Evil Number" by Jan Orwat. % (3) Feedback in comments from Peng Liu. % (4) Problem Problem 1237. "It's race time! Write a faster function than the test suite call of unique()." by Jeremy. % Note: The Time Trial section does not check accuracy; that is done above. % Initialise x = 'Dbodfm Pqfsbujpo Qipfojy jnnfejbufmz & ftdbqf.'; cutoffTimeBig = 1000; % Maximum allowable walltime (in milliseconds) to run function in a loop with qBig iterations. for dummy = 1 : 20, disp(' . '); end; % Run once, untimed? includeOverheads = false; if includeOverheads, solution = decode( x ); end; % *** PRELIMINARY TIMING *** % In case the submitted function has a lot of text output, % get an estimate based on just a few iterations % Initialise qSmall = 50; qBig = 5000; t0 = clock; % Loop for i = 1 : qSmall solution = decode( x ); end; % Compute and display elapsed time. dt = etime(clock, t0) * 1000; disp(' -----=====----- ') fprintf('Your wall time to decode %u messages = %i msec.\n\r', qSmall, floor(dt)) fprintf('Your APPROXIMATE wall time to decode %u messages would be ~ %i msec.\n\r', qBig, ceil(dt * qBig / qSmall)) disp(' -----=====----- ') for dummy = 1 : 20, disp(' . '); end; % *** 'OFFICIAL' TIMING *** % Re-initialise timer t0 = clock; t0_cpu = cputime; % Loop for i = 1 : qBig solution = decode( x ); end; % Compute and display elapsed time. for dummy = 1 : 20, disp(' . '); end; disp(' -----=====|||||=====----- ') dt = etime(clock, t0) * 1000; fprintf('Your wall time to decode %u messages = %i msec.\n\r', qBig, floor(dt)) dt_cpu = (cputime - t0_cpu) * 1000; fprintf(' ( Your CPU time for this = %i msec. ) \n\r', floor(dt_cpu)) fDecode = @() decode(x); dt_timeit = timeit( fDecode ) * 1000; fprintf(' [ Your ''timeit'' time to decode %u messages = %i msec. ] \n\r', qBig, ceil(dt_timeit * qBig)) % Display a size-based score. all_nodes = mtree('decode.m', '-file'); % This is the default in Cody. str_nodes = mtfind(all_nodes, 'Kind', 'STRING'); eq_nodes = mtfind(all_nodes, 'Kind', 'EQUALS'); print_nodes = mtfind(all_nodes, 'Kind', 'PRINT'); expr_nodes = mtfind(all_nodes, 'Kind', 'EXPR'); size_score = count(all_nodes) ... +sum(str_nodes.nodesize-1) ... +2*(count(expr_nodes) ... +count(print_nodes) ... -count(eq_nodes)); fprintf('Your size-based score = %i.\n\r', size_score) % Report revised performance score. combinedScore = size_score + min( 200, floor(dt*(500/qBig)) ); fprintf('Your combined score = %i.\n\r', combinedScore) disp(' -----=====|||||=====----- ') % Now disallow any candidate solutions that are TOO SLOW! if dt > cutoffTimeBig, fprintf('Sorry, your submission is TOO SLOW. It must be able to finish within %u milliseconds.\n\r', cutoffTimeBig) end; assert( dt <= cutoffTimeBig, 'Exceeded time limit specified in Test Suite.' )

. . . . . . . . . . . . . . . . . . . . s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediately & escape.' s = struct with fields: shift: 2 message: 'Cancel Operation Phoenix immediate...

Exceeded time limit specified in Test Suite.