Changeable words: Difference between revisions

Added Wren
(→‎{{header|Raku}}: Only show each word pair once)
(Added Wren)
Line 377:
52. upperclassmen >> upperclassman
done...
</pre>
 
=={{header|Wren}}==
Using the Hamming Distance between two equal length strings which needs to be 1 here:
<lang ecmascript>import "io" for File
import "/fmt" for Fmt
 
var hammingDist = Fn.new { |s1, s2|
s1 = s1.toList // in case there are non-ASCII characters
s2 = s2.toList // ditto
var count = 0
var i = 0
while (i < s1.count) {
if (s1[i] != s2[i]) count = count + 1
i = i + 1
}
return count
}
 
var wordList = "unixdict.txt" // local copy
var words = File.read(wordList).trimEnd().split("\n").where { |w| w.count > 11 }.toList
var count = 0
System.print("Changeable words in %(wordList):")
for (word1 in words) {
for (word2 in words) {
if (word1 != word2 && word1.count == word2.count) {
if (hammingDist.call(word1, word2) == 1) {
count = count + 1
Fmt.print("$2d: $-14s -> $s", count, word1, word2)
}
}
}
}</lang>
 
{{out}}
<pre>
Changeable words in unixdict.txt:
1: aristotelean -> aristotelian
2: aristotelian -> aristotelean
3: claustrophobia -> claustrophobic
4: claustrophobic -> claustrophobia
5: committeeman -> committeemen
6: committeemen -> committeeman
7: committeewoman -> committeewomen
8: committeewomen -> committeewoman
9: complementary -> complimentary
10: complimentary -> complementary
11: confirmation -> conformation
12: conformation -> confirmation
13: congresswoman -> congresswomen
14: congresswomen -> congresswoman
15: councilwoman -> councilwomen
16: councilwomen -> councilwoman
17: craftsperson -> draftsperson
18: draftsperson -> craftsperson
19: eavesdropped -> eavesdropper
20: eavesdropper -> eavesdropped
21: frontiersman -> frontiersmen
22: frontiersmen -> frontiersman
23: handicraftsman -> handicraftsmen
24: handicraftsmen -> handicraftsman
25: incommutable -> incomputable
26: incomputable -> incommutable
27: installation -> instillation
28: instillation -> installation
29: kaleidescope -> kaleidoscope
30: kaleidoscope -> kaleidescope
31: neuroanatomy -> neuroanotomy
32: neuroanotomy -> neuroanatomy
33: newspaperman -> newspapermen
34: newspapermen -> newspaperman
35: nonagenarian -> nonogenarian
36: nonogenarian -> nonagenarian
37: onomatopoeia -> onomatopoeic
38: onomatopoeic -> onomatopoeia
39: philanthrope -> philanthropy
40: philanthropy -> philanthrope
41: prescription -> proscription
42: proscription -> prescription
43: schizophrenia -> schizophrenic
44: schizophrenic -> schizophrenia
45: shakespearean -> shakespearian
46: shakespearian -> shakespearean
47: spectroscope -> spectroscopy
48: spectroscopy -> spectroscope
49: underclassman -> underclassmen
50: underclassmen -> underclassman
51: upperclassman -> upperclassmen
52: upperclassmen -> upperclassman
</pre>
9,482

edits