Ad
  • Custom User Avatar
  • Default User Avatar
    'It should work for random inputs too:'
    # talks about your function, announces random tests
    
    'expected [ 3, +0, 5, 5, +0, +0, +0, 4 ]'
    # this shows what your function returned
    
    'to deeply equal [ 3, +0, 4 ]'
    # this shows the correct return value
    

    "What your function returned, (shows you)

    was not what should have been returned." (shows you)

    the only thing it doesn't show is the input

  • Default User Avatar

    I'm sorry for a stupid question but can anyone explain what is - It should work for random inputs too: expected [ 3, +0, 5, 5, +0, +0, +0, 4 ] to deeply equal [ 3, +0, 4 ], not sure I understand this phrase(js)

  • Custom User Avatar

    Thank you for the clarification! Done

  • Custom User Avatar

    You need to take 2 chairs from the first room, that's why the right answer for the first case is [2].
    The same for the other case, you take 4 chairs from the first room.

    "Game On" is for the case when you literally don't need chairs, like in the sample tests:

    test.assert_equals(meeting([["XX", 2], ["XXXX", 6], ["XXXXX", 4]], 0), "Game On")
    
  • Custom User Avatar

    Thanks for the detailed explanaition!

    Smth similar to https://www.codewars.com/kata/584703d76f6cf6ffc6000275, as far as I understand now. Math makes things easier

  • Custom User Avatar

    Testing for [['XXX', 5], ['', 1], ['XXXXX', 3], ['XX', 1], ['', 9], ['XXXXXXX', 10], ['X', 9], ['XXXXXXXXXX', 5], ['XXXXX', 7], ['XXXXXXXXXX', 10], ['XXXXXXX', 0], ['XXXX', 8]] and 2

    It should work for random inputs too: 'Game On' should equal [2]

    i need to find 2 chairs. But there are 2 free chairs in the very first room => i don't need the chairs => Game On, right? But why [2]?

    Testing for [['XX', 8], ['XXXXXXXX', 6], ['XXXXXXX', 10], ['XX', 4], ['XXXXXXXX', 10], ['XXXXXX', 3], ['XXX', 6], ['XXXXXXXXX', 9]] and 4
    It should work for random inputs too: 'Game On' should equal [4]

    same issue. There are 6 free chairs out of 8 in the room 0. Why do i need to find extra [4]?

  • Default User Avatar

    If I am not wrong, Unnamed was using a mathematical approach and it levarages the periodicity of the sequence in terms of odd and even terms. While most of us is using iterative approach.The provided solution is more efficient for larger values.

    Regarding you question:

    1. First part (n mod 6)
      If you know the parity of two numbers, you also know the parity of their sum. So the sequence is defined as: f(n) = f(n-1)+f(n-2)+f(n-3)+f(n-4)+f(n-5)
      Initial values: f(0)=0, f(1)=1, f(2)=1, f(3)=2, f(4)=4. If you compute the parity, you will be able to see a pattern (i.e.odd, odd, even, even, even, even, odd, odd, even, even, even, even,...). So you will be able to notice the pattern repeats every 6 terms.

    2. The list [0,1,2,2,2,2],
      The above pattern (section 1) gives us the cumulative count of odd numbers.
      For n, there are (n/6) complete segments of 6 terms. Therefore, 2x(n/6) gives the number of odd terms in these complete segments.
      The remainder, n mod 6, tells us where in the 6-term segment we are. The list [0,1,2,2,2,2] gives the cumulative count of odd numbers up to that point in the cycle.

    In summary, the sequence has a repeating pattern of parity due its linear definition and the properties of of parity over addition. Therefore, this repeating pattern allowed him, Unnamed, to use a mathematical approach.

  • Custom User Avatar

    incredible!
    could you please explain the magic numbers? (2, 6, [0, 1, 2, 2, 2, 2])
    and how is it even possible to come up with such a solution!?

  • Custom User Avatar
  • Custom User Avatar

    i pass all tests except starting with 'x'. could you please clarify on the leading 0's rule? Input 'xx': 3 should be close to 2.5 with absolute or relative margin of 0.01 - don't understand how it's possible

  • Custom User Avatar

    thanks! Now got it. Need to distribute ALL the numbers in a certain order + the given list is unordered. The description is not that accurate(

  • Custom User Avatar

    [5, 6, 7, 8], [5, 6, 7, 8], [6, 7, 8, 9]

    Both tests are fine. The numbers should be consecutive within each group.

  • Custom User Avatar

    and how this can be True? test.assert_equals(consecutive_nums([6, 6, 6, 9, 7, 8, 7, 5, 8, 5, 7, 8], 4), True)

  • Custom User Avatar

    is it True? Description, Examples, consecutive_nums([1, 2, 3, 6, 2, 3, 4, 7, 8], 3) ➞ True, # [1, 2, 3], [2, 3, 4], [6, 7, 8]

  • Loading more items...