Ad
  • Custom User Avatar

    I couldn't submit the same solution because of timeout.

  • Custom User Avatar

    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.

  • Custom User Avatar

    It has approximate time complexity O(n log n). ( I already thought so. But I checked. ) Your C or assembly solution might have time complexity O(n), but will very, very probably also have O(n log n).

    No, length is not cached. But even without, time complexity is something like (O m n log n) with m the length of the longest group. That's approximately a small constant except in extreme cases. Caching length would be a good thing here.

  • Custom User Avatar

    shorter than mine!

  • Custom User Avatar

    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! :)

  • Custom User Avatar

    You mean that you'd rather have abs (x1-x2) instead of abs(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.

  • Custom User Avatar

    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!

  • Custom User Avatar

    Very insightful usage of scanr.

  • Custom User Avatar
    • "AC AC 3H 4D 5S" is better than "AC AC 2H 4D 5S" (at least when I tested it)
    • Description says: "From above definition it is clear that Hand can contain any number of cards", so random testing works correctly
  • Custom User Avatar

    Errors 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.

  • Custom User Avatar

    Second is from Arrow.

  • Custom User Avatar

    Yep, it's rather frustrating.