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

  • Ruby 3.0 should be enabled, see this to learn how to do it

  • Could someone explain to me how this solution works? Not quite familiar with how regular expressions work.

    My main trouble areas are {4,} and match.group(0). Not quite sure as to what these accomplish.

  • That's because sample tests are wrong since Test.expect takes only one argument :)

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

  • Well, that's after I changed this:

          s1, s2 = two_sum(arr.dup, target)
        rescue NameError
          s1, s2 = twoSum(arr.dup, target)

    For this:

        if defined?(two_sum)
          s1, s2 = two_sum(arr.dup, target)
          s1, s2 = twoSum(arr.dup, target)

    Any idea why the first one gave that error instead of the out of bounds? I mean, hiding the real problem.

  • main.rb:14:in `block (2 levels) in two_sum': undefined method `+' for nil:NilClass (NoMethodError)
    	from main.rb:12:in `loop'
    	from main.rb:12:in `block in two_sum'
    	from main.rb:11:in `loop'
    	from main.rb:11:in `two_sum'

    As it says, one of the arguments of the + inside the inner loop is nil, which means the index is out of bounds.

  • I saw it, but still I have no idea why that happens, sorry. Maybe someone who's more fluent in Ruby could find out why.

  • Hi Chrono79. I pasted the the solution that passes about 10 tests before getting that weird NoMethod error above if you want to replicate. Thank you :-)

  • Thanks!! TIL something ;-)

  • Yes, it was a painful Kata that left mixed impressions. Not so bad actually =)

  • If you need a hint, maybe this will help.

    1. If count == null, it should be manually coerced to 32 (the default function parameter does not work for null).
    2. If you are converting an argument to a string, consider this:
       (-1).toString(2); //       --> "-1"
       (-1 >>> 0).toString(2); // --> "11111111111111111111111111111111"

    And this as well:

    (x | 0)   UInt32 --> Int32
    (x >>> 0) Int32 --> UInt32

    PS: Please don't mark this comment as a spoiler. It's just a hint for solving a poorly composed Kata.

  • 104 tests passed 116 tests failed. I would say this kata is kinda mess.

    • Python new test framework should be used (Refer this & this for more detail)

    • Ruby 3.0 should be enabled (Refer this & this for more detail)

  • Loading more items...