Cody

Problem 1873. Break it up! Break it up!

Solution 319339

Submitted on 14 Sep 2013
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

This solution is outdated. To rescore this solution, sign in.

Test Suite

Test Status Code Input and Output
1   Pass
% Clean workspace !/bin/cp partitions.m safe !/bin/rm *.* !/bin/mv safe partitions.m % Clean user's function from some known jailbreaking mechanisms functions={'!','feval','eval','str2func','str2num','regex','system','dos','unix','perl','assert','fopen','write','save','setenv','path','please'}; fid = fopen('partitions.m'); st = char(fread(fid)'); for n = 1:numel(functions) st = regexprep(st, functions{n}, 'error(''No fancy functions!''); %','ignorecase'); end fclose(fid) % Force a function header, and comment first code's line (the supposedly users' function header) st = sprintf('function y = partitions(x)\n%%%s', st); fid = fopen('partitions.m' , 'w'); fwrite(fid,st); fclose(fid)

ans = 0 ans = 0

2   Pass
%% x = 1;y_correct = 1;assert(isequal(partitions(x),y_correct))

y = 1

3   Pass
%% x = 5;y_correct = 7;assert(isequal(partitions(x),y_correct))

y = 7

4   Pass
%% x = 50;y_correct = 204226;assert(isequal(partitions(x),y_correct))

y = 204226

5   Pass
%% assert(isequal(partitions(partitions(partitions(partitions(5)))),476715857290));

y = 7 y = 15 y = 176 y = 4.7672e+11

6   Pass
%% assert(isequal(partitions(partitions(partitions(6))),526823));

y = 11 y = 56 y = 526823

7   Pass
%% assert(isequal(partitions(partitions(12)),10619863));

y = 77 y = 10619863

8   Fail
%% assert(isequal(partitions(199),3646072432125))

Error: Assertion failed.

9   Fail
%% P=arrayfun(@(x) partitions(x),10:10:100); y_correct=[42 627 5604 37338 204226 966467 4087968 15796476 56634173 190569292]; assert(all(isequal(P,y_correct)))

Error: Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false.