Changeable words: Difference between revisions
Content deleted Content added
→{{header|Wren}}: Added libheader. |
Added Go |
||
Line 128:
upperclassman ---> upperclassmen
upperclassmen ---> upperclassman</pre>
=={{header|Go}}==
{{trans|Wren}}
<lang go>package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"unicode/utf8"
)
func hammingDist(s1, s2 string) int {
r1 := []rune(s1) // in case there are non-ASCII characters
r2 := []rune(s2) // ditto
if len(r1) != len(r2) {
return 0
}
count := 0
for i := 0; i < len(r1); i++ {
if r1[i] != r2[i] {
count++
if count == 2 {
break // don't care about counts > 2
}
}
}
return count
}
func main() {
wordList := "unixdict.txt"
b, err := ioutil.ReadFile(wordList)
if err != nil {
log.Fatal("Error reading file")
}
bwords := bytes.Fields(b)
var words []string
for _, bword := range bwords {
s := string(bword)
if utf8.RuneCountInString(s) > 11 {
words = append(words, s)
}
}
count := 0
fmt.Println("Changeable words in", wordList, "\b:")
for _, word1 := range words {
for _, word2 := range words {
if word1 != word2 && hammingDist(word1, word2) == 1 {
count++
fmt.Printf("%2d: %-14s -> %s\n", 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>
=={{header|Raku}}==
|