Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement