Ad
  • Custom User Avatar

    Because it is building a new string so it is appending a new value onto the string for each pass of loop. I did similar thing, except I had result += a ? b : c

  • Custom User Avatar

    Please use the spoiler flag next time you are posting code.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Cannot get it, why we put += next to result. Can smb explain, pls?

  • Custom User Avatar

    The tests in Ruby are fine. Closing.

  • Custom User Avatar
  • Default User Avatar

    Approved.

  • Custom User Avatar

    ruby test cases are wrong , the final test shows 89 hours but it should be 6 hours and 31 minutes

  • Default User Avatar

    Ok. I've updated.

    Many thanks.

  • Default User Avatar

    I believe "Pair" was the worst offender.

    Find all the groups in that range where each member of the group within the range.

    This still needs changing! Doesn't make sense. After removing extra use of "range" and adding "is", it becomes:

    Find all the groups where each member is within the range.

    The range requirement has however already been stated. This says nothing and can be removed. It is also not the groups that should be found (it is the smallest values of the groups) so it is non-information.

    Suggestion:

    Given a range(a, b), return the sum of the lowest member of each group.

    Redundancies are good for descriptions here at Codewars.

    Not when that makes relevant information sparsely scattered between other repeated information! The use of different terms and formats additionally makes it difficult to tell whether something is new information or something that's already been said. There's also something to be said for brevity and being able to fit an idea in ones head.

    I also think implied rules/constraints are Good Things when faithfully implementing the description results in the implications being included. The area of a rectangle is also the area of a square. The sum of empty is 0.
    I understand this may raise questions, but that might actually be a good thing. But I also understand that the traffic might not be desirable for you.

  • Default User Avatar

    I've removed the word pair. Using the words group & grouping now.

    This Kata defines group/grouping as having 2 or more members that have the same ratio. This is is not a notation issue. The definitions are given as follows:

    We shall say that (6,28,496) is a grouping with a ratio of 2.
    We shall say that (30,140) is a grouping with a ratio of 12/5.
    

    Removed nil requirement for Ruby.

    Redundancies are good for descriptions here at Codewars. The point has to be belabored, otherwise its never understood. I know this, because I've authored more than 100 Katas. Anyway, I hope the changes work now.

  • Default User Avatar

    The word "pair" is misleading. It is not what you mean and it isn't previously defined in the description either. Please use something like "grouping of size 2 or more" instead.

    I find this notation to be confusing: (6,28,496) because it suggests that this is a tuple which in turn suggests that it is fixed length, or rather lacks length and has three values. It's a group and a group isn't specifically three values, it's a list. Ergo [6, 28, 496]

    (6,28) and (30,140) are the only pairs in which every member of a pair is 0 <= n < 200. The sum of the lowest members of each pair is 6 + 30 = 36.

    Here you are introducing a second notation for a range (the other one being range(a, b)). Better if you use the same one everywhere.

    nil in Ruby is unneccessary, the sum of zero things is 0.

    Find all the pairs in that range where each member of the pairs within the range.

    "range" is mentioned twice but only has meaning once, and it doesn't make sense/English syntax error

    The task isn't fully described, it leans too much on examples.

    For solve(1,500), do not include all (6,28) & (6,496) & (28,496). Count the group once by including 6 only.

    That's redundant if you describe what a group is. Also, group is now a third term (grouping pair group) for the same thing.

    There are many formats used for list:

    (6,28,496)
    1, 2, 3, 5, 6, 10, 15 & 30
    1, 2, 4, 5, 7, 10, 14, 20, 28, 35, 70, 140
    [6, 12, 30, 40, 66, 78, 80, 84, 102]
    

    They're all the same thing. One format.

  • Default User Avatar

    Good question.

    • The divisors of 4 are: 1, 2, & 4 and their sum is 7. Now, 7/4.0 = 1.75.
    • The divisors of 165 are 1, 3, 5, 11, 15, 33, 55 & 165 and their sum is 288. Now, 288/165.0 = 1.7454545454545454

    The two are different. Note that I've used 7/4.0 and not 7/4 because I want a float, not a truncated integer. You can use the following trick: if x = 7 and y = 4, then the ratio is x/(y * 1.0) to get a float. x/y gives an integer.

    Use this logic and you will see that (5,133) cannot be grouped together because 1.2030075187969924 != 1.2, and so on

    The trick here is to use a data structure that keeps track of the ratios you have already found, so that if you come across that ratio again, you ignore because you are only taking the lowest member in any ratio. It's quite simple😊

  • Custom User Avatar

    i didn't get it. between 1 to 200 there are a lot of harmony numbers [4, 165]=1.75 [5, 133] =1.2 [6, 28]=2 [8, 52]=8... and all of them are 0<=n<200 what should i do with them?

  • Default User Avatar

    Although this would not be regarded as a 'clever' solution i still think this way is the best solution. One for loop, instead of three to be a 'single liner'.

  • Loading more items...