function SubKakuro(Number,Spread)
%MAY NOT BE OPTIMISED ALGORITHM!!!!!BUT WORKS FINE...
clc
disp('please wait...CPU is processing...')
%Sub KAKURO
%3 < Number < 45
if Number<3 && Number>45,
disp('Number entered is not VALID');
return;
end
if Spread<2 && Number>9,
disp('Spread entered is not VALID');
return;
end
Limit=0;
for ii=1:Spread
Limit=10*Limit+ii;
end
%StoreKaku(1,1:9)=[0 0 0 0 0 0 0 0 0];
count=1;
for ii=12:Limit %awesome limits
n=9;
%storing digits of number
N=ii;
for jj=1:n
Kaku(ii-11,jj)=mod(N,10);
N=floor(N/10);
if N~=0, n=jj+1; end
end
Kaku(ii-11,:)=sort(Kaku(ii-11,:),'descend');
%excluding single digited numbers
if size(find(Kaku(ii-11,:)>0),2)<=1,
continue;
end
%checking the repetition of digits
valid=1;
for kk=1:9
if size(find(Kaku(ii-11,:)==kk),2)>1,
valid=0;
break;
end
end
if valid==0, continue; end
%converting back to number
[r,v]=find(Kaku(ii-11,:));
NumKaku(count)=0;
for ll=1:length(v)
NumKaku(count)=10*NumKaku(count)+Kaku(ii-11,ll);
end
%checking for repetition of number
for kk=1:count-1,
if NumKaku(kk)==NumKaku(count),
count=count-1;
break;
end
end
count=count+1;
end
%counting the possibilities
count=1;
for ii=1:length(NumKaku)
N=NumKaku(ii);
sum=0;
for jj=1:9
sum=sum+mod(N,10);
N=floor(N/10);
if N~=0, n=jj+1; end
if N==0, break; end
end
if (sum==Number && Spread==jj),
Kakuro(count)=str2num(fliplr(num2str(NumKaku(ii))));
count=count+1;
end
end
clc
%displaying the digits
if count<2,
disp('no possibilities...')
else
disp(Kakuro)
end
%next step would be storing all the possibilities (limit # 123456789)
% so that they is no need to run the code each and every time...