Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Replace
seen := make(map[string]int, len(gloves))
toseen := make(map[string]int)
in my solution, and you will get identical benchmark.If you think what I have done is considered "clever" I have bad news for you..
These solutions that try and be clever and test for % 2 inside the loop are doing way too many tests. Here's the results:
BenchmarkKata2 is for this code. BenchmarkKata1 is for code that does not check inside the for loop, and has a separate for loop over the map to add "seen" / 2 to the total number of pairs.
"Clever" in codewars seems to be a positive mark. In reality, you don't want to be clever in your code. Especially with Go, one of the key values of the language is that it is straight-forward and simple. In this case, clever is not even faster, it is almost 50% slower.
What if the string contains runes that are neither uppercase or lowercase (not a letter, but a number or symbol)? unicode considers them neither upper or lowercase. len(str) also returns the number of bytes in the string, not the number of runes.