Skip to content

Instantly share code, notes, and snippets.

@caelifer
Created November 22, 2016 10:34
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 caelifer/e2cca06d0e3d44f3d12a2bfe1ad0620f to your computer and use it in GitHub Desktop.
Save caelifer/e2cca06d0e3d44f3d12a2bfe1ad0620f to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"unicode"
)
func main() {
for _, tc := range []string{
"the quick brown fox jumps over the lazy dog",
"the quick brown fox jumped over the lazy dog",
} {
if isPangram(tc) {
fmt.Println("pangram")
} else {
fmt.Println("not pangram")
}
}
}
func isPangram(s string) bool {
mm := mm()
for _, r := range []rune(s) {
if unicode.IsLetter(r) {
t := unicode.ToLower(r)
if _, ok := mm[t]; ok {
mm[t] = true
} else {
return false
}
}
}
for _, v := range mm {
if !v {
return false
}
}
return true
}
func mm() map[rune]bool {
m := make(map[rune]bool, 28)
for i := 'a'; i <= 'z'; i++ {
m[i] = false
}
return m
}
@caelifer
Copy link
Author

Live code - https://play.golang.org/p/J5b98kTsnJ

Output:

pangram
not pangram

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment