MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Solution 174002

Submitted on 6 Dec 2012 by Richard Zapor

Correct

119Size
`This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.`

### Test Suite

Test
Code Input and Output
1
Pass

```%%
tic
toc
```
```ans =
/users/msssystem12/analysis_in.txt
Elapsed time is 0.252808 seconds.
```
2
Pass

```%%
fid=fopen('analysis_in.txt','r');
min_elements_expected=[2 0 1 2 0 3 4];
qty=fscanf(fid,'%i',1);
for q=1:qty
n = fscanf(fid,'%i %i\n',2)'; % cols / rows
A=zeros(n)'; % Format is colmns, rows
for i=1:n(2)
strv = fgetl(fid);
A(i,:) = strv - '0';
end
strv=fgetl(fid);
Sample=strv - '0';
min_elements=Chem_analysis(A,Sample);
assert(isequal(min_elements,min_elements_expected(q)));
end % for q
fclose(fid);
% The C Winning Solution
% #include <iostream>
% #include <fstream>
% #include <string>
% using namespace std;
% int testcases;
% int n, m;
% int now;
% int best;
% string goal;
% string s[1000];
% void search(int i, string status)
% {
% 	if (i == n)
% 	{
% 		if (status == goal)
% 		{
% 		 if ((best < 0) || (now < best)) best = now;
% 		}
% 		return;
% 	}
% 	search(i + 1, status);
% 	string tmp = status;
% 	for (int j = 0; j < m; j ++)
% 	{
% 		if (s[i][j] == '1') tmp[j] = '1';
% 	}
% 	now ++;
% 	search(i + 1, tmp);
% 	now --;
% }
% int main()
% {
% 	ifstream inf("analysis.in");
% 	inf >> testcases;
% 	for (int testcase = 1; testcase <= testcases; testcase ++)
% 	{
% 		cout << "Data Set " << testcase << ":" << endl;
% 		inf >> m >> n;
% 		for (int i = 0; i < n; i ++)
% 			inf >> s[i];
% 		inf >> goal;
% 		best = -1;
% 		string ini = "";
% 		for (int i = 0; i < m; i ++)
% 			ini = ini + "0";
% 		now = 0;
% 		search(0, ini);
%  if (best < 0) cout << "Impossible" << endl; else cout << best << endl;
% 		cout << endl;
% 	}
% 	inf.close();
% 	return 0;
% }
%
%
%
```