Each of
TSRABVOLUE, RSBAOVTULE, OSBURVLETA, UBOSLRVEAT, VLSOAEBTRU, AUBTOELSRV, BEOVSALRUT, LTOVABERSU, ELTUSBROVA is a perfect square.
Determine the key, knowing that none of the 9 numbers can contain any leading zero.
clc,clearvars
squares={'TSRABVOLUE', 'RSBAOVTULE', 'OSBURVLETA','UBOSLRVEAT', ...
'VLSOAEBTRU', 'AUBTOELSRV', 'BEOVSALRUT', 'LTOVABERSU', 'ELTUSBROVA'};
lets='TSRABVOLUE';
perm=lets(perms(1:10));
for i=1:length(perm)
p=perm(i,:);
good=true;
for squ=1:length(squares)
sq=str2double(translate(squares{squ},p));
sr=round(sqrt(sq));
if sr^2~=sq
good=false;
break
end
end
if good
disp(p)
for squ=1:length(squares)
sq=str2double(translate(squares{squ},p));
sr=round(sqrt(sq));
fprintf('%s %d %d \n',squares{squ},sq,sr)
end
end
end
function tr=translate(a,code)
b=zeros(1,length(a));
for i=1:10
c=code(i);
idx=a==c;
b(find(idx))=char(string(i-1));
end
tr=char(b);
end
finds
0123456789
STROUVABLE
translation square
root
TSRABVOLUE 1026753849 32043
RSBAOVTULE 2076351489 45567
OSBURVLETA 3074258916 55446
UBOSLRVEAT 4730825961 68781
VLSOAEBTRU 5803697124 76182
AUBTOELSRV 6471398025 80445
BEOVSALRUT 7935068241 89079
LTOVABERSU 8135679204 90198
ELTUSBROVA 9814072356 99066
The codes are listed in numeric order and since each begins with a different letter other than zero, the sequence of first letters represent the digit 1 - 9 in order.
|
Posted by Charlie
on 2024-01-15 08:37:02 |