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.
I couldn't submit the same solution because of timeout.
Each length is calculated twice, so I can't even tell without testing if caching would help or not. And the complexity is just
O(n * log n)
, the group lengths are not independent of the list length, they are made of the same items.It has approximate time complexity
O(n log n)
. ( I already thought so. But I checked. ) Your C or assembly solution might have time complexityO(n)
, but will very, very probably also haveO(n log n)
.No,
length
is not cached. But even without, time complexity is something like(O m n log n)
withm
the length of the longestgroup
. That's approximately a small constant except in extreme cases. Caching length would be a good thing here.shorter than mine!
Yeah, you're right about the Codewars grouping! The main one that shows up lacks the spacing, though! I assume this was the first such solution.
Take care! :)
You mean that you'd rather have
abs (x1-x2)
instead ofabs(x1-x2)
. That's right, it would be much more natural in Haskell. In fact, I think that's what I wrote, but I think that codewars ignores white space when grouping solutions.Having parenthesis right beside the function call in Haskell seems so strange to me! Nothing wrong with it, just don't see it much.
but since this is an easier problem if any of you are new to haskell it's worth noting that function calls don't actually require parenthesis like they do in other programming languages (such as Python, C, etc.)
f x
instead of
f(x)
is perfectly fine :). It's nice because you get less noise with all of the parenthesis. I'm sure lots of you know about this, but sometimes when people format things like this they're secretly trying to make Haskell one of their other favourite programming languages ;).
Cheers!
Very insightful usage of
scanr
.Hand
can contain any number of cards", so random testing works correctlyErrors in the test so far:
"AC AC 3H 4D 5S" should be better than "AC AC 2H 4D 5S", not vice versa (pair with kicker)
Random testing generates hands with more than five cards.
Second is from Arrow.
Yep, it's rather frustrating.