clearvars,clc
digs='0123456789';
idx=combinator(10,5,'p');
codes=digs(idx);
i=1;
while i<length(codes)
code=codes(i,:);
if code(1)=='0'
codes(i,:)=[];
else
i=i+1;
end
end
% Now form:
% vList -- values of valid double twelves
% pList -- corresponding patterns (codes) for dbl twelves
% dList -- 1 if pattern is one of a duplicate (or multiple) set
% these lists are all the same length and refer to the
% same coding of TWELVE.
vList=[]; pList=string.empty; dList=[];
% codes will be ordered lists of 4 digits
% representing t, w, e,l,v
lets='twelv'; ii=0;
for i=1:length(codes)
code=codes(i,:);
ns='twelve';
for j=1:5
ns=strrep(ns,lets(j),code(j));
end
n=str2double(ns);
v=2*n;
vs=char(string(v));
tst=setdiff(ns,vs);
% eleven + eleven must contain no digits from eleven
if length(tst)==5
ii=ii+1;
vList(ii)=v;
p=string(pttrn([ns vs]));
if ismember(p,pList)
dList(find(pList==p))=1;
dList(ii)=1;
end
pList(ii)=p;
end
end
% create a list of patterns with unique numbers
% (if TWELVE is unique then so is twice that value)
goodSubs=find(dList==0);
goodPats=pList(goodSubs);
goal=23;
ct=0; pat12=pttrn('twelve');
fid=fopen('c:\words\words.txt','r');
while ~feof(fid)
w=lower(fgetl(fid));
if (length(w)==6 || length(w)==7) ...
&& isequal(w,lower(w))
if length(setdiff('twelv',w))==5
if length(unique(w))<7
ct=ct+1;
codePat=pttrn(['twelve' w]);
if ismember(codePat,goodPats)
pf=goodPats==codePat;
sb=find(pf);
sb=goodSubs(sb);
matchNum=vList(sb);
for i=1:length(matchNum)
if sod(matchNum(i))==goal
matchNum(1)=matchNum(i);
end
end
if sod(matchNum(1))==goal
fprintf('%s %d %d %d %d\n',w,matchNum(1),matchNum(1)/2,sod(matchNum(1)),length(matchNum))
end
end
end
end
end
end
fclose('all');
function cd=pttrn(n)
rp='a';
ns=char(string(n));
repl=repmat(' ',1,length(ns));
for i=1:length(ns)
if repl(i)==' '
ix=strfind(ns,ns(i));
repl(ix)=rp;
rp=char(rp+1);
end
end
cd=repl;
end
The line
goal=23;
replaces one where goal was 24, as nothing was found for that.
For 23:
sum TWELVE sod
across 903722 451861 23 1
burgoo 903722 451861 23 1
bypass 903722 451861 23 1
cashoo 903722 451861 23 1
congii 903722 451861 23 1
goniff 903722 451861 23 1
kaross 903722 451861 23 1
kumiss 903722 451861 23 1
misadd 903722 451861 23 1
morass 903722 451861 23 1
payoff 903722 451861 23 1
ripoff 903722 451861 23 1
ruboff 903722 451861 23 1
runoff 903722 451861 23 1
scruff 903722 451861 23 1
shroff 903722 451861 23 1
skidoo 903722 451861 23 1
cruyff 903722 451861 23 1
hindoo 903722 451861 23 1
johann 903722 451861 23 1
So
TWELVE 451861
TWELVE 451861
------ ------
ACROSS 903722