Ad
  • Custom User Avatar
    • 20 sees only 30, and therefore can be the lowest value (1)
    • 30 sees 20 and 40, and must be higher than 20 (1), and is therefore (2)
    • 40 sees 30 and 30, and must be higher than both, but we do not yet know what the value of the 30 at index 3 is

    It's not that the second 30 takes precedence exactly, it's that the team that scored 40 must be higher than both of its neighbours - and the second 30 can be deduced to have a value of 3... but as you've discovered, not by taking into account only the information on its left hand side.

    How might we figure that out?

  • Custom User Avatar

    As said in description:

    A team can know the bonus amount of its adjacent team, if the
    score of the adjacent team is lower than itself.

    This means the first team (team who scored 30) will know the bonus amount of the second team (team who scored 20), the second team will know the amount of bonus from the third team (team who scored 10). Also said in description that:

    If a team finds that its bonus is no higher than the adjacent team whose
    score is lower than itself, the team will not be satisfied

    First we know that the third team knew none of the other teams' score, therefore they get the lowest of 1 bonus. Secondly, the second team knew the score of third team (which means second team have a higher amount of score), therefore they needed a bonus amount higher than 1, which is 2. We can also use the same logic to get the amount of bonus for the first team, they needed a bonus higher than 2, which is 3. Then we add all the bonuses together to get:

    1+2+3=6k, so the answer is 6 for minimum bonus. Sorry if my explaination isn't clear enough :)

  • Custom User Avatar

    You're on the right track thinking about recursive algorithms and your deductions so far are almost correct. If permutations(5) is made up of (5-1) == 4 branches as you say, each having 11 leaves, how might we derive that number 11? You say it's permutation(n-1) - <something> but permutations(5-1) == permutations(4) == 9 as you say, which is smaller than 11... so something is being added, not subtracted.

  • Custom User Avatar

    I believe this is the 2kyu kata for anyone interested https://www.codewars.com/kata/evaluate-mathematical-expression/

  • Custom User Avatar

    Duplicate of a 2 kyu kata, except without parentheses. I can literally copy-paste my JS or Python solution from the 2 kyu one and paste here and it will immediately pass.

  • Default User Avatar

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

  • Default User Avatar

    I also faced the same issue. However between 307 and 317, 311 is also a prime number so 307 and 317 are not perfect 10 gap prime numbers. The question does mention about this issue. I will be putting it here so that you can understand it better.
    "gap(6,100,110) --> nil or {0, 0} or ... : between 100 and 110 we have 101, 103, 107, 109 but 101-107 is not a 6-gap because there is 103 in between and 103-109 is not a 6-gap because there is 107 in between."(Taken from the original question).
    So the kata expects you to return 2 primes with the gap 'g' such that there are no primes among the numbers between those numbers.

  • Custom User Avatar

    307 and 317 are not consecutive primes.

  • Custom User Avatar

    Moreover Python's interpreter makes it easy to handle, indicating the line of your code that contains the instruction that made your program crash.

  • Custom User Avatar

    IndexError: pop from empty list

    This error is very clear. You tried to use .pop() on an empty list. Whereever this error comes from, it is certain that it's coming from your code.

    It's not enough to just log inputs, it's also important to log all relevant variables along the way, and see the exact point where your program crashes.

  • Default User Avatar

    dec2FactString(n) factString2Dec(n) : these two functions were in a first version (long ago) of the kata. They have been replaced by fact_string_2_dec / dec_2_fact_string (to have snake_case) without problem (read "testing1" and "testing2" in "Sample tests".

    Read the complete output of the tests, in particular the last part:

    /workspace/default/solution.py", line 14, in <listcomp>
        mapped = [_fact(int(tpl[0])) * int(tpl[1]) for tpl in  tpls]
    ValueError: invalid literal for int() with base 10: 'A'
    

    The error is in your code "solution.py", line 14.
    Cheers.

  • Custom User Avatar

    the index of the smallest digit

    That's not true, read the description and the examples again.

    the index i of the digit d you took, i as small as possible

    i as small as possible, it doesn't say d as small as possible.

  • Custom User Avatar

    You've probably already done that kata, but still, I'm having a same issue, mainly because author inserted huge numbers, so a loop is going to work for a long time. Have to find the other way, I'd say more, but I don't want to make spoilers.

  • Default User Avatar

    @m_mistroni, sorry about this issue, I hope everything works fine for you now

  • Custom User Avatar

    Raising an issue, the control function is mutating the input.

  • Loading more items...