There are currently 118 elements in the Periodic Table, each Symbol consisting of one or two letters.
Some words can be constructed from the set of these Symbols and some cannot.
For example "calculus" has two "elemental representations":
C Al C U Lu S
C Al Cu Lu S
Moreover we will add one point to a word's "score" for every letter in the word which can appear as the first letter of a two-letter symbol and also as the second letter of a two-letter symbol in different valid elemental representations of the same word.
The word "calculus" scores zero points because the only difference between its two reprentations is C U vs Cu.
On the other hand, "snow" can be:
S N O W
Sn O W
S No W
Since the letter "n" appears both in Sn and No, "snow" gets one point.
Your challenge: If k is the maximum score of the set of all words in the English language, try to find an example word for each score from 1 to k.
(In reply to
re(6): Not the scoring method I had in mind, but ... by Larry)
clearvars
global names symbols build ways
fid=fopen('c:b5 projectslooblechemical elements.txt','r');
names=string.empty; symbols=string.empty;
while ~feof(fid)
l=fgetl(fid);
f=find(l==' ');
symbols(end+1)=string(l(f(1)+1:f(2)-1));
names(end+1)=string(l(f(2)+1:f(3)-1));
if names(end)==""
names(end)=[];
symbols(end)=[];
end
end
fclose(fid);
names=string.empty;
fid=fopen('c:wordswords.txt','r');
while ~feof(fid)
names(end+1)=fgetl(fid);
if ~isequal(names(end),lower(names(end)))
names(end)=[];
break
end
end
sets={}; counts=[];
count=0;
for i=1:length(names)
build='';
ways={};
count=0;
addon(i,1);
if length(ways)>1
w=ways{1};
w=w(w~=' ');
for pos=2:length(w)-1
found=false;
for j=1:length(ways)
Rep=strtrim(ways{j});
Rep=Rep(Rep~=' ');
for k=1:length(ways)
if j~=k
rep=strtrim(ways{k});
rep=rep(rep~=' ');
for psn=pos
if Rep(psn)==upper(Rep(psn)) && ...
Rep(psn+1)>='a' && Rep(psn+1)<='z'
if rep(psn)==lower(Rep(psn))
found=true;
end
end
end
end
if found
break
end
end
if found
break
end
end
if found
count=count+1;
end
end
end
if count>0
sets{end+1}=ways;
counts(end+1)=count;
end
end
function addon(i,wh)
global names symbols build ways
if wh==1
build='';
end
rest= lower(extractBetween(names(i),wh,length(char(names(i)))));
for j=1:length(symbols)
trial= lower(symbols(j));
f=strfind(rest,trial);
if ~isempty(f)
if f(1)==1
build=[ build char(symbols(j))];
if length(build)==strlength(names(i))
% disp([build ' ' char(names(i))])
ways{end+1}='';
for k=1:length(build)
if build(k)==upper(build(k))
ways{end}=[ways{end} sprintf('%s',' ')];
end
ways{end}=[ways{end} sprintf('%s',build(k))];
end
else
addon(i,wh+strlength(trial));
end
build=extractBefore(build,length(build)-strlength(trial)+1);
end
end
end
end
This should do what I now think is what was sought:
A sampling of the sorted output (Some are just the first two alphabetically, but in some instances I substituted one or two that were later alphabetically so as to be more common words):
1
Ac Ce P Ta N C Es
Ac Ce P Ta N Ce S
1
Ac Ce P Ts
Ac Ce Pt S
2
Ac Ar In Es
Ac Ar I N Es
Ac Ar I Ne S
2
Ac C Es S Es
Ac C Es Se S
Ac Ce S S Es
Ac Ce S Se S
3
Ac Ce P Ta Ti O N
Ac Ce Pt At I O N
3
C La S H Es
C La S He S
Cl As H Es
Cl As He S
4
Al F Re S C O
Al F Re S Co
Al F Re Sc O
Al Fr Es C O
Al Fr Es Co
4
B Ra C Es
B Ra Ce S
Br Ac Es
5
Ar C C O Si N Es
Ar C C O Si Ne S
Ar C C O S In Es
Ar C C O S I N Es
Ar C C O S I Ne S
Ar C C Os In Es
Ar C C Os I N Es
Ar C C Os I Ne S
Ar C Co Si N Es
Ar C Co Si Ne S
Ar C Co S In Es
Ar C Co S I N Es
Ar C Co S I Ne S
5
As S As Si N At Es
As S As Si Na Te S
As S As S In At Es
As S As S I N At Es
As S As S I Na Te S
6
F Ra C As Es
F Ra Ca S Es
F Ra Ca Se S
Fr Ac As Es
6
F Ra Te Rn I Ti Es
Fr At Er N I Ti Es
Fr At Er Ni Ti Es
7
F La Tl In Es
F La Tl I N Es
F La Tl I Ne S
Fl At Li N Es
Fl At Li Ne S
7
P At Er N Al I Sm
P At Er Na Li Sm
Pa Te Rn Al I Sm
8
F Ra Te Rn Al I Sm
Fr At Er N Al I Sm
Fr At Er Na Li Sm
8
F Ra Te Rn Al I Sm S
Fr At Er N Al I Sm S
Fr At Er Na Li Sm S
9
P Al At In At Es
P Al At I N At Es
P Al At I Na Te S
Pa La Ti N At Es
Pa La Ti Na Te S
>>
Edited on July 17, 2022, 6:23 pm
|
Posted by Charlie
on 2022-07-17 17:14:23 |