5 kyu

How many strings use all symbols of a given alphabet at least once

Description
Loading description...
Algorithms
Mathematics
  • Please sign in or sign up to leave a comment.
  • ahmet_popaj Avatar

    More like a math challenge, however nice.

  • trashy_incel Avatar

    suggested tag: combinatorics

  • Kacarott Avatar
  • dfhwze Avatar

    Nice kata. Approved at kyu 5.

  • dfhwze Avatar

    Does this sequence naturally extend with larger 'a' like in your example?

    if n == 5 and a == 4:
        return (4 ** 5) - (4) - (4 * (3 * (2**5 - 2))) - (4 * (3**5 - 3 - 3*(2**5 - 2)))  # 60 should equal 240
    
    • dfhwze Avatar

      nvm, -1 should have been (-1) :s

      Question marked resolved by dfhwze 3 years ago
    • benjaminzwhite Avatar

      Hi @dfhwze , thanks so much for trying my kata.

      To answer your question: Yes, but remember if you're going to calculate recursively like this that the multiplications for the various "missing" symbols will probably involve binomial coefficients rather than just linear 4*, 3*, 2* etc.

      For example, if we read the part in the description for n=5, a=3 which says:

      "So, for each of the 3 choices of F, G, or H there are exactly 2**5 - 2 = 30 forbidden strings in which exactly one of those symbols is missing, but not two of them."

      in the above, the "3 choices" here is actually obtained from 3_choose_1 binomial coefficient, because you are choosing 1 symbol to omit from the 3 available.

      When you have n=5 and a=4, as you consider the strings missing exactly 1,2,3 symbols, the new terms will involve binomial coefficients like this:

      "With a = 4 symbols {F,G,H,I} there are 4_choose_2 = 6 (i.e. NOT just 4) ways of selecting 2 "missing symbols" to not use from these 4 sybmbols."

    • dfhwze Avatar

      This comment has been hidden.

    • dfhwze Avatar

      I'm not sure what would be best moving forward. Either you update the description with the 5,4 case, or you mark your previous comment as a spoiler. I do think the difficulty level of this kata depends on your decision ;)

    • benjaminzwhite Avatar

      This comment has been hidden.

    • benjaminzwhite Avatar

      This comment has been hidden.

    • dfhwze Avatar

      Let's leave it as is. People are free to browse the comments section if they seek some hints.

    • benjaminzwhite Avatar

      This comment has been hidden.