Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 86093

Submitted on 5 May 2012 by Richard Zapor

Correct

296Size
Leading solution size is 145.
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
 
%%
    astr='a'; % []
    bstr='a';
    cstr='aa';
  y_correct = [];
assert(isequal(crypto_add(astr,bstr,cstr),y_correct))

                    
2
Pass
 
%%
    astr='ab'; % []
    bstr='ab';
    cstr='ab';
  y_correct = [];
assert(isequal(crypto_add(astr,bstr,cstr),y_correct))

                    
3
Pass
 
%%
   astr='abcdefghij'; %[]
   bstr='abcdefghij';
   cstr='aabcdefghij';
  y_correct = [];
assert(isequal(crypto_add(astr,bstr,cstr),y_correct))

                    
4
Pass
 
%%
   astr='coca'; % 8186
   bstr='cola'; % 8106
   cstr='oasis'; % 16292
y_correct = [8186 8106 16292];
assert(isequal(crypto_add(astr,bstr,cstr),y_correct))

                    
5
Pass
 
%%
   astr='xxx';% 999
   bstr='b';  %   1
   cstr='baaa'; % 1000
y_correct = [999 1 1000];
assert(isequal(crypto_add(astr,bstr,cstr),y_correct))

                    
6
Pass
 
%%
   astr='ma';  % 89 9 98
   bstr='a';
   cstr='am'
y_correct = [89 9 98];
assert(isequal(crypto_add(astr,bstr,cstr),y_correct))
cstr =
am
7
Pass
 
%%
   astr='bmtran'; % 951740 or  651740
   bstr='winner'; % 630087 y   930087
   cstr='tmeteor';% 1581827   1581827
y_correct1 = [951740 630087 1581827];
y_correct2 = [651740 930087 1581827];
y_out=crypto_add(astr,bstr,cstr)
solved= isequal(y_out,y_correct1) || isequal(y_out,y_correct2)
assert(solved)
y_out =
      651740      930087     1581827
solved =
     1
8
Pass
 
%%
% For those that like to hard code answers
asum=0;
while asum<1234567890
 avec=randperm(10)-1
 asum=polyval(avec,10);
end
bsum=0;
while bsum<1234567890
 bvec=randperm(10)-1
 bsum=polyval(bvec,10);
end
csum=asum+bsum;
%csum=csum+20000000000; %To create []
cvec=int2str(csum)-'0' % separate puzzle question
alpha_vec=randperm(10); % randomize the alphabet
alpha='abcdefghij';
astr='';
for i=1:length(avec)
 astr=[astr alpha(alpha_vec(avec(i)+1))];
end
bstr='';
for i=1:length(bvec)
 bstr=[bstr alpha(alpha_vec(bvec(i)+1))];
end
cstr='';
for i=1:length(cvec)
 cstr=[cstr alpha(alpha_vec(cvec(i)+1))];
end
astr
bstr
cstr
y_correct = [asum bsum csum];
assert(isequal(crypto_add(astr,bstr,cstr),y_correct))
avec =
     4     9     3     0     5     6     1     8     7     2
bvec =
     7     2     3     8     6     0     5     9     4     1
cvec =
  Columns 1 through 10
     1     2     1     6     9     1     6     7     8     1
  Column 11
     3
astr =
aidfbchgje
bstr =
jedgcfbiah
cstr =
hehcihcjghd
9
Pass
 
%%
% For those that like to hard code answers
asum=0;
while asum<1234567890
 avec=randperm(10)-1
 asum=polyval(avec,10);
end
bsum=0;
while bsum<1234567890
 bvec=randperm(10)-1
 bsum=polyval(bvec,10);
end
csum=asum+bsum;
csum=csum+20000000000; %To create []
cvec=int2str(csum)-'0' % separate puzzle question
alpha_vec=randperm(10); % randomize the alphabet
alpha='abcdefghij';
astr='';
for i=1:length(avec)
 astr=[astr alpha(alpha_vec(avec(i)+1))];
end
bstr='';
for i=1:length(bvec)
 bstr=[bstr alpha(alpha_vec(bvec(i)+1))];
end
cstr='';
for i=1:length(cvec)
 cstr=[cstr alpha(alpha_vec(cvec(i)+1))];
end
y_correct = [];
assert(isequal(crypto_add(astr,bstr,cstr),y_correct))
avec =
     9     8     5     7     3     2     0     1     4     6
bvec =
     7     8     2     4     5     9     3     1     0     6
cvec =
  Columns 1 through 10
     3     7     6     8     1     9     1     3     2     5
  Column 11
     2