Cody

# Problem 42710. Cleaner

Solution 2540160

Submitted on 13 Jun 2020
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
%{ ╔═══════════════════════════════════════════╗ ║ Please, play against the given problem, ║ ║ not against weaknesses of the Test Suite. ║ ║ There is no 100% efficient method to ║ ║ prevent cheating solutions, so there is ║ ║ no extra protection used. I'd be happy if ║ ║ there were no solutions with code hidden ║ ║ in strings only to decrease the "size". ║ ║ Little hacks, used in order to complete ║ ║ the task, are allowed, but please don't ║ ║ change the filename. All suggestions are ║ ║ welkome. ║ ║ Thanks & have fun. Jan ║ ╚═══════════════════════════════════════════╝ %}

2   Fail
x = 1; y_correct = 1; b = cleaner % no ";" only "b" stays alive assert(numel(who)==1)

Unrecognized function or variable 'x'. Error in cleaner (line 11) x(x<0 | x>10) = NaN; Error in Test2 (line 3) b = cleaner

3   Fail
x = 1; y_correct = 1; b = cleaner; % cleaner not activated assert(numel(who)==3)

Unrecognized function or variable 'x'. Error in cleaner (line 11) x(x<0 | x>10) = NaN; Error in Test3 (line 3) b = cleaner;

4   Fail
x = 1; y_correct = 1; z = 'hello' b = {cleaner} % cleaner wrapped in cell, no action assert(numel(who)==4)

z = 'hello'

Unrecognized function or variable 'x'. Error in cleaner (line 11) x(x<0 | x>10) = NaN; Error in Test4 (line 4) b = {cleaner}

5   Fail
x = 1; y_correct = 1; b = cleaner; assert(isequal(who,{'b';'x';'y_correct'})) b assert(isequal(who,{'b'}))

Unrecognized function or variable 'x'. Error in cleaner (line 11) x(x<0 | x>10) = NaN; Error in Test5 (line 3) b = cleaner;

6   Fail
b1 = cleaner; b2 = cleaner; b3 = cleaner; b4 = cleaner; assert(isequal(who,{'b1';'b2';'b3';'b4'})) assert(isequal(b1,b2,b3,b4,cleaner)) b3 % clean other cleaners, only "b3" survives here assert(isequal(who,{'b3'}))

Unrecognized function or variable 'x'. Error in cleaner (line 11) x(x<0 | x>10) = NaN; Error in Test6 (line 1) b1 = cleaner;

7   Fail
x = 1; y_correct = 1; b = cleaner assert(numel(who)==1) x = 1; y = 2 assert(numel(who)==3) a = b assert(isequal(who,{'a'}))

Unrecognized function or variable 'x'. Error in cleaner (line 11) x(x<0 | x>10) = NaN; Error in Test7 (line 3) b = cleaner

8   Fail
% cleaning other workspace (of created below function in temp.m) %{ function out = temp(in) x = 1; y = 2; assert(numel(who)==3) k = in out = who; end %} f1 = fopen('temp.m','w'); fprintf(f1,'function out=temp(in)\n x=1;\n y=2;\n assert(numel(who)==3)\n k=in\n out=who;\nend'); fclose(f1); clear; x = 1; y = 2; z = cleaner; a = temp(z) assert(isequal(who,{'a';'x';'y';'z'})) assert(isequal(a,{'k'}))

Unrecognized function or variable 'x'. Error in cleaner (line 11) x(x<0 | x>10) = NaN; Error in Test8 (line 17) z = cleaner;

### Community Treasure Hunt

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

Start Hunting!