Update
This commit is contained in:
31
go/isogram/README.md
Normal file
31
go/isogram/README.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Isogram
|
||||
|
||||
Determine if a word or phrase is an isogram.
|
||||
|
||||
An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter.
|
||||
|
||||
Examples of isograms:
|
||||
|
||||
- lumberjacks
|
||||
- background
|
||||
- downstream
|
||||
|
||||
The word *isograms*, however, is not an isogram, because the s repeats.
|
||||
|
||||
To run the tests simply run the command `go test` in the exercise directory.
|
||||
|
||||
If the test suite contains benchmarks, you can run these with the `-bench`
|
||||
flag:
|
||||
|
||||
go test -bench .
|
||||
|
||||
For more detailed info about the Go track see the [help
|
||||
page](http://exercism.io/languages/go).
|
||||
|
||||
## Source
|
||||
|
||||
Wikipedia [https://en.wikipedia.org/wiki/Isogram](https://en.wikipedia.org/wiki/Isogram)
|
||||
|
||||
## Submitting Incomplete Problems
|
||||
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||
|
23
go/isogram/isogram.go
Normal file
23
go/isogram/isogram.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package isogram
|
||||
|
||||
import "strings"
|
||||
|
||||
const testVersion = 1
|
||||
|
||||
func IsIsogram(inp string) bool {
|
||||
used := make(map[rune]int)
|
||||
inp = strings.ToLower(inp)
|
||||
for _, l := range inp {
|
||||
switch l {
|
||||
case '-':
|
||||
continue
|
||||
case ' ':
|
||||
continue
|
||||
}
|
||||
if used[l] > 0 {
|
||||
return false
|
||||
}
|
||||
used[l] = used[l] + 1
|
||||
}
|
||||
return true
|
||||
}
|
50
go/isogram/isogram_test.go
Normal file
50
go/isogram/isogram_test.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package isogram
|
||||
|
||||
import "testing"
|
||||
|
||||
var testCases = []struct {
|
||||
word string
|
||||
expected bool
|
||||
}{
|
||||
{"duplicates", true},
|
||||
{"eleven", false},
|
||||
{"subdermatoglyphic", true},
|
||||
{"Alphabet", false},
|
||||
{"thumbscrew-japingly", true},
|
||||
{"Hjelmqvist-Gryb-Zock-Pfund-Wax", true},
|
||||
{"Heizölrückstoßabdämpfung", true},
|
||||
{"the quick brown fox", false},
|
||||
{"Emily Jung Schwartzkopf", true},
|
||||
{"éléphant", false},
|
||||
}
|
||||
|
||||
func TestIsIsogram(t *testing.T) {
|
||||
for _, c := range testCases {
|
||||
if IsIsogram(c.word) != c.expected {
|
||||
t.Fatalf("FAIL: Word %q, expected %v, got %v", c.word, c.expected, !c.expected)
|
||||
}
|
||||
|
||||
t.Logf("PASS: Word %q", c.word)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkIsIsogram(b *testing.B) {
|
||||
b.StopTimer()
|
||||
for _, c := range testCases {
|
||||
b.StartTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
IsIsogram(c.word)
|
||||
}
|
||||
|
||||
b.StopTimer()
|
||||
}
|
||||
}
|
||||
|
||||
const targetTestVersion = 1
|
||||
|
||||
func TestTestVersion(t *testing.T) {
|
||||
if testVersion != targetTestVersion {
|
||||
t.Errorf("Found testVersion = %v, want %v.", testVersion, targetTestVersion)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user