Last active
March 27, 2017 00:00
-
-
Save teknoraver/72105a65dfe9d7af09dfe08da57490c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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