Created
July 31, 2018 18:35
-
-
Save jaye-ross/b5644fcef5d81ad887631a40e7d995ff to your computer and use it in GitHub Desktop.
Calculate Bell numbers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://en.wikipedia.org/wiki/Partition_of_a_set#Counting_partitions | |
bell = function(n) { | |
ifelse(n > 0, | |
sum(Vectorize(function(n, k) { | |
choose(n - 1, k) * bell(k) | |
}, "k")(n, 0:(n - 1))), | |
1) | |
} | |
bell(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment