Ad
  • Custom User Avatar

    Because you can't do [1 1]. And I have already explained it in the post above yours.

  • Custom User Avatar

    1 x 1 = 1, that is why it should be in there. The number and itself happens to be a divisor. There's also no special criteria that says the array of divisors has to be unique.

    The example provided in the description of the kata for the number 246:
    [1, 246, 2, 123, 3, 82, 6, 41]

    1 x 246 = 246
    2 x 123 = 246
    3 x 82 = 246
    6 x 41 = 246

    Makes sense, since all the numbers are in the array.

    When we try to produce the first step for number "1":
    1 x 1 = 1

    It should produce [1,1].

    Can you mention why it shouldn't be [1,1]?

  • Custom User Avatar

    schanjr why do you say?

    Divisors of 1 are [1,1]

    There is only one divisor of 1 and that's 1, why do you write it twice there?

  • Default User Avatar

    Buddy, just because people can (and did) hardcode solutions to solve this issue, doesn't mean your kata doesn't have an issue.

  • Custom User Avatar

    It got marked as Best Practices, but here the idea is to solve it yourself instead of using libraries...

  • Default User Avatar

    Not a kata issue. Before posting issues look at the top of the page: 433 people passed the Ruby kata (out of 18127). If there were errors in the kata someone would have seen them before you. Cheers.

  • Custom User Avatar

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

  • Custom User Avatar

    Probably the best solution here in terms of algorithm. The one that got upvoted the most looks prettiest.

  • Custom User Avatar

    Blows my mind everytime I see a short solution like this.

  • Custom User Avatar

    It's linear, so it scales ok. Sure it's not optimized for very different lengths case, but optimized != best practice.

    Best practice is right compromise between optimization and code clarity.

  • Custom User Avatar

    short solution is what I would say, but not Best Practices. Does not scale well if one list is a lot longer than the other one. It would store too much into the memory.

  • Custom User Avatar

    From my understanding, your "copy" just means creating separate memory address, and not referencing to the original object directly.
    Your instructions can be challenging for those without CS major.

  • Custom User Avatar

    I actually never knew this. This is about 25% faster than the traditional method of 2 ** 5. Going to treasure this nugget of knowledge forever.