Ad
  • Custom User Avatar

    Although this isn't a requirement for this kata, a minor improvement would be to use isSpace instead of isAlpha so characters that aren't alphabetical are captured correctly.

  • Custom User Avatar

    Omg wtf HAHAHHAHAHHA

  • Custom User Avatar

    It does not work for this sudoku for example :

    [[5 3 4 6 7 8 9 2 2]
    [6 7 2 2 9 5 3 4 8]
    [2 9 8 3 4 2 5 6 7]
    [8 5 9 7 6 2 4 2 3]
    [4 2 6 8 5 3 7 9 2]
    [7 2 3 9 2 4 8 5 6]
    [9 6 2 5 3 7 2 8 4]
    [2 8 7 4 2 9 6 3 5]
    [3 4 5 2 8 6 2 7 9]]

    I replaced all 1s in a valid sudoku by 2s.

  • Custom User Avatar

    euyemura,
    combination(k) returns an Enumerable, not an Array of all the combinations. The Enumerable is lazy and will only find out the next combination when you call for the next value. When calling an Enumerable method like reduce on the return value of combination(k) you can break out of the loop and return early in you want, hence not wasting cycles. In this kata, I would break out early if my current sum matches t exactly. The solution above does not do this so will always have to sum all combinations so there is a bit of room for performance improvement, but not much.

  • Custom User Avatar

    Can't do better than linear time, constant memory. I suspect something's fishy in the tests.

  • Custom User Avatar

    Sorry, late response. You can pass a block into ls.combination(k) instead of to the .map function, which would allow you to exit early. However, the target distance is a limit, not a minimum. Since each combination you try might be higher than your last max and lower than the limit, we must visit every single combination to be sure of our answer.

    Good thinking though =D

  • Custom User Avatar

    Hello! yours is top voted so i wanted to ask you and everyone else, is there a better way to do this than to use .combination(k)? If i'm not not mistaken this method creates every single combination, as opposed to doing something like making every combination in order until it creates an array with a sum that is over the target distance and then stopping. I ended up using combination as well, but isn't the time efficiency of it pretty bad? Your solution is super elegant, just want to understand if there's more efficient ways.

  • Custom User Avatar
    • It looks like 1 was fixed long ago
    • description was clarified
    • raised new issue on lack of tests
  • Custom User Avatar

    Would you resubmit your translation? I couldn't approve the current version (description changed)

    Oh, just make sure you put the empty function in the "solution setup":

    def relatively_prime(n, l)
      # your code here
    end
    

    Cheers

  • Custom User Avatar

    No, I think the kata is clear about being sequential by 1.

  • Custom User Avatar

    I like your solution, it's very well organized, but I think the sequential part is wrong. The instructions just say the number has to be sequential, but doesn't specify that it has to be +/- 1 for each number. Even though the test cases don't have any other types of sequential sequences, your solution would be wrong if the number was 741 for instance. That's still a sequential number in my opinion, even though it doesn't decrement by 1. Overall nice job though, much more concise than mine!

    EDIT: I just refactored my solution using some stuff from yours, but with a method for sequential numbers that works for any sequence (I think), if you're interested in taking a look.

  • Custom User Avatar

    Yeah good point, this still isn't fixed. Thought it was an issue with my code as I was using the "permutation" method!

  • Custom User Avatar

    Very nice solution, I like it!

    Please have a look at https://github.com/bbatsov/ruby-style-guide, it's better to use &&, || etc. operators over keywords like 'and', 'or' and the 'return' keyword is not needed.

  • Custom User Avatar

    Date is in the title!

  • Custom User Avatar

    How about adding the 'date and time' tag?

  • Loading more items...