Bobinas P4G
  • Login
  • Public

    • Public
    • Groups
    • Popular
    • People

Conversation

Notices

  1. La FÊe Verte (absinthe@qoto.org)'s status on Tuesday, 08-Oct-2019 22:29:29 UTC La Fée Verte La FÊe Verte
    • 🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą
    • Kyle

    @khird @freemo

    How's this look?
    def N(x):
    if (x < 0):
    return 0
    if (x == 0 or x == 1):
    return 1
    return N(x-1) + N(x-2)

    def N135(x):
    if (x < 0):
    return 0
    if (x == 0):
    return 1
    return (N135(x-1) + N135(x-3) + N135(x-5))

    def NArr(x, arr):
    if (x < 0):
    return 0
    if (x == 0):
    return 1
    return sum([NArr(x - i, arr) for i in arr])

    def main():
    for n in range(10):
    print(n, N(n))

    for n in range(10):
    print(n, N135(n))

    for n in range(10):
    print(n, NArr(n, [1,3,5]))

    if __name__ == "__main__":
    main()

    In conversation Tuesday, 08-Oct-2019 22:29:29 UTC from qoto.org permalink
    • 🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą repeated this.
    • La FÊe Verte (absinthe@qoto.org)'s status on Tuesday, 08-Oct-2019 23:56:10 UTC La Fée Verte La FÊe Verte
      • 🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą
      • Kyle

      @khird @freemo

      Okay, so with all that, here is the actual longhand using the permutations, but I am not sure how to handle this if I passed an array of numbers like in the 1,3,5 example

      def NFact(x):
      def fact(x):
      _fact = 1
      for i in range(1, x+1):
      _fact = _fact * i
      return _fact

      def r_NFact(num):
      twos = x - num
      ones = x - (2 * twos)
      if ones < 0:
      return 0
      return r_NFact(num - 1) + ( fact(num) // (fact(ones) * fact(twos)))
      return r_NFact(x)

      In conversation Tuesday, 08-Oct-2019 23:56:10 UTC permalink
      🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą repeated this.
    • 🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą (freemo@qoto.org)'s status on Wednesday, 09-Oct-2019 05:06:05 UTC 🎓 Dr. Freemo :jpf: 🇳🇱 🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą
      • Kyle

      @Absinthe

      Just a suggestion, if you use the binomial coefficient notation when talking about permutations you might find it much easier to reason over, at least I do.

      @khird

      In conversation Wednesday, 09-Oct-2019 05:06:05 UTC permalink
    • 🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą (freemo@qoto.org)'s status on Wednesday, 09-Oct-2019 10:41:53 UTC 🎓 Dr. Freemo :jpf: 🇳🇱 🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą
      • Kyle

      @Absinthe

      read as "k pick n"

      \[
      \binom{n}{k} = \frac{n!}{k! (n-k)!}
      \]

      @khird

      In conversation Wednesday, 09-Oct-2019 10:41:53 UTC permalink
    • 🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą (freemo@qoto.org)'s status on Wednesday, 09-Oct-2019 10:43:03 UTC 🎓 Dr. Freemo :jpf: 🇳🇱 🎓 Dr. Freemo :jpf: đŸ‡ŗđŸ‡ą
      • Kyle

      @Absinthe

      read as "n choose k"

      \[
      \binom{n}{k} = \frac{n!}{k! (n-k)!}
      \]

      @khird

      In conversation Wednesday, 09-Oct-2019 10:43:03 UTC permalink

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • Privacy
  • Source
  • Version
  • Contact

Bobinas P4G is a social network. It runs on GNU social, version 2.0.1-beta0, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All Bobinas P4G content and data are available under the Creative Commons Attribution 3.0 license.