Skip to content

Instantly share code, notes, and snippets.

@teknoraver
Last active March 27, 2017 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teknoraver/72105a65dfe9d7af09dfe08da57490c1 to your computer and use it in GitHub Desktop.
Save teknoraver/72105a65dfe9d7af09dfe08da57490c1 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
/*
* example run:
*
* go run isogram.go /usr/share/dict/italian |awk -F"'" '{if(length($1) > 9)print length($1), $1}' |sort -gr
*/
func isIsogram(word string) bool {
myMap := make(map[rune]int, len(word))
for _, v := range word {
if _, p := myMap[v]; p {
myMap[v]++
} else {
myMap[v] = 1
}
}
last := myMap[rune(word[0])]
for _, v := range myMap {
if v != last {
return false
}
last = v
}
return true
}
func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "usage:", os.Args[0], "<file>")
os.Exit(1)
}
file, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
word := scanner.Text()
word_ascii := word
word_ascii = strings.Replace(word_ascii, "à", "a", -1)
word_ascii = strings.Replace(word_ascii, "è", "e", -1)
word_ascii = strings.Replace(word_ascii, "è", "e", -1)
word_ascii = strings.Replace(word_ascii, "ì", "i", -1)
word_ascii = strings.Replace(word_ascii, "ò", "o", -1)
word_ascii = strings.Replace(word_ascii, "ù", "u", -1)
if isIsogram(word_ascii) {
fmt.Println(word)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment