Created
November 22, 2016 10:34
-
-
Save caelifer/e2cca06d0e3d44f3d12a2bfe1ad0620f 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 ( | |
"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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Live code - https://play.golang.org/p/J5b98kTsnJ
Output: