Textonyms: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 1,391:
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.</pre>
 
=={{header|Perl 6}}==
<lang perl6>my $src = 'unixdict.txt';
 
my @words = slurp($src).lines.grep(/ ^ <alpha>+ $ /);
 
my @dials = @words.classify: {
.trans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
=> '2223334445556667777888999922233344455566677778889999');
}
 
my @textonyms = @dials.grep(*.value > 1);
 
say qq:to 'END';
There are {+@words} words in $src which can be represented by the digit key mapping.
They require {+@dials} digit combinations to represent them.
{+@textonyms} digit combinations represent Textonyms.
END
 
say "Top 5 in ambiguity:";
say " ",$_ for @textonyms.sort(-*.value)[^5];
 
say "\nTop 5 in length:";
say " ",$_ for @textonyms.sort(-*.key.chars)[^5];</lang>
{{out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.
 
Top 5 in ambiguity:
269 => amy any bmw bow box boy cow cox coy
729 => paw pax pay paz raw ray saw sax say
2273 => acre bard bare base cape card care case
726 => pam pan ram ran sam san sao scm
426 => gam gao ham han ian ibm ibn
 
Top 5 in length:
25287876746242 => claustrophobia claustrophobic
7244967473642 => schizophrenia schizophrenic
666628676342 => onomatopoeia onomatopoeic
49376746242 => hydrophobia hydrophobic
2668368466 => contention convention</pre>
 
=={{header|Phix}}==
Line 1,790 ⟶ 1,748:
3 tests passed
3 tests passed</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
<lang perl6>my $src = 'unixdict.txt';
 
my @words = slurp($src).lines.grep(/ ^ <alpha>+ $ /);
 
my @dials = @words.classify: {
.trans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
=> '2223334445556667777888999922233344455566677778889999');
}
 
my @textonyms = @dials.grep(*.value > 1);
 
say qq:to 'END';
There are {+@words} words in $src which can be represented by the digit key mapping.
They require {+@dials} digit combinations to represent them.
{+@textonyms} digit combinations represent Textonyms.
END
 
say "Top 5 in ambiguity:";
say " ",$_ for @textonyms.sort(-*.value)[^5];
 
say "\nTop 5 in length:";
say " ",$_ for @textonyms.sort(-*.key.chars)[^5];</lang>
{{out}}
<pre>There are 24978 words in unixdict.txt which can be represented by the digit key mapping.
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.
 
Top 5 in ambiguity:
269 => amy any bmw bow box boy cow cox coy
729 => paw pax pay paz raw ray saw sax say
2273 => acre bard bare base cape card care case
726 => pam pan ram ran sam san sao scm
426 => gam gao ham han ian ibm ibn
 
Top 5 in length:
25287876746242 => claustrophobia claustrophobic
7244967473642 => schizophrenia schizophrenic
666628676342 => onomatopoeia onomatopoeic
49376746242 => hydrophobia hydrophobic
2668368466 => contention convention</pre>
 
=={{header|REXX}}==
Line 1,948 ⟶ 1,949:
["2668368466", ["contention", "convention"]]
</pre>
 
=={{header|VBScript}}==
<lang vb>Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
"\unixdict.txt",1)
Set objKeyMap = CreateObject("Scripting.Dictionary")
With objKeyMap
.Add "ABC", "2" : .Add "DEF", "3" : .Add "GHI", "4" : .Add "JKL", "5"
.Add "MNO", "6" : .Add "PQRS", "7" : .Add "TUV", "8" : .Add "WXYZ", "9"
End With
 
'Instantiate or Intialize Counters
TotalWords = 0
UniqueCombinations = 0
Set objUniqueWords = CreateObject("Scripting.Dictionary")
Set objMoreThanOneWord = CreateObject("Scripting.Dictionary")
 
Do Until objInFile.AtEndOfStream
Word = objInFile.ReadLine
c = 0
Num = ""
If Word <> "" Then
For i = 1 To Len(Word)
For Each Key In objKeyMap.Keys
If InStr(1,Key,Mid(Word,i,1),1) > 0 Then
Num = Num & objKeyMap.Item(Key)
c = c + 1
End If
Next
Next
If c = Len(Word) Then
TotalWords = TotalWords + 1
If objUniqueWords.Exists(Num) = False Then
objUniqueWords.Add Num, ""
UniqueCombinations = UniqueCombinations + 1
Else
If objMoreThanOneWord.Exists(Num) = False Then
objMoreThanOneWord.Add Num, ""
End If
End If
End If
End If
Loop
 
WScript.Echo "There are " & TotalWords & " words in ""unixdict.txt"" which can be represented by the digit key mapping." & vbCrLf &_
"They require " & UniqueCombinations & " digit combinations to represent them." & vbCrLf &_
objMoreThanOneWord.Count & " digit combinations represent Textonyms."
 
objInFile.Close</lang>
{{out}}
<pre>There are 24978 words in "unixdict.txt" which can be represented by the digit key mapping.
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.</pre>
 
=={{header|Tcl}}==
Line 2,083 ⟶ 2,031:
able bake bald bale cake calf
</pre>
 
=={{header|VBScript}}==
<lang vb>Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) &_
"\unixdict.txt",1)
Set objKeyMap = CreateObject("Scripting.Dictionary")
With objKeyMap
.Add "ABC", "2" : .Add "DEF", "3" : .Add "GHI", "4" : .Add "JKL", "5"
.Add "MNO", "6" : .Add "PQRS", "7" : .Add "TUV", "8" : .Add "WXYZ", "9"
End With
 
'Instantiate or Intialize Counters
TotalWords = 0
UniqueCombinations = 0
Set objUniqueWords = CreateObject("Scripting.Dictionary")
Set objMoreThanOneWord = CreateObject("Scripting.Dictionary")
 
Do Until objInFile.AtEndOfStream
Word = objInFile.ReadLine
c = 0
Num = ""
If Word <> "" Then
For i = 1 To Len(Word)
For Each Key In objKeyMap.Keys
If InStr(1,Key,Mid(Word,i,1),1) > 0 Then
Num = Num & objKeyMap.Item(Key)
c = c + 1
End If
Next
Next
If c = Len(Word) Then
TotalWords = TotalWords + 1
If objUniqueWords.Exists(Num) = False Then
objUniqueWords.Add Num, ""
UniqueCombinations = UniqueCombinations + 1
Else
If objMoreThanOneWord.Exists(Num) = False Then
objMoreThanOneWord.Add Num, ""
End If
End If
End If
End If
Loop
 
WScript.Echo "There are " & TotalWords & " words in ""unixdict.txt"" which can be represented by the digit key mapping." & vbCrLf &_
"They require " & UniqueCombinations & " digit combinations to represent them." & vbCrLf &_
objMoreThanOneWord.Count & " digit combinations represent Textonyms."
 
objInFile.Close</lang>
{{out}}
<pre>There are 24978 words in "unixdict.txt" which can be represented by the digit key mapping.
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.</pre>
 
=={{header|zkl}}==
10,343

edits