Problem 1388. Numbered lottery balls into cells
You are running a lottery, and have a number of different balls numbered 1 to N. Your job is to figure out how many different ways these balls can go into k different buckets. The only stipulation is that each bucket must have at least one ball in it.
For example, if you have 4 balls and 2 buckets, you can divide them up seven different ways:
- 123, 4
- 124, 3
- 134, 2
- 234, 1
- 12, 34
- 13, 24
- 14, 23
The order of the buckets does not matter, so (12, 34) is the same as (34, 12). Likewise, the order of the balls does not matter, so (12, 34) is the same as (21, 43). Good luck!
Solution Stats
Problem Comments
-
4 Comments
Great catch! That one is now fixed. That happened when I was copying the results of the array of values from 1-12 for lottery(12,x). I guess the values for 11 and 12 were on the next line, and I accidentally deleted one of the 6s in 66 for lottery(12,11). I'll double check the rest of them when I get back on my machine that has MATLAB on it. I'm rescoring now.
Stirling numbers of the second kind.
Can we please stop banning keywords such as "if" in test suites? I know it's intended to crack down on cheating and look-up solutions, but it also interferes with legitimate solutions that need case distinctions.
Solution Comments
Show commentsGroup

Sequences & Series I
- 14 Problems
- 87 Finishers
- Sum all integers from 1 to 2^n
- Integer sequence - 2 : Kolakoski sequence
- Sum all integers from 1 to 2^n
- Project Euler: Problem 2, Sum of even Fibonacci
- Sum of first n terms of a harmonic progression
- Project Euler: Problem 6, Natural numbers, squares and sums.
- Integer Sequence - II : New Fibonacci
- Project Euler: Problem 2, Sum of even Fibonacci
- Project Euler: Problem 6, Natural numbers, squares and sums.
- Find the stride of the longest skip sequence
- Sum the Infinite Series
- Return the Fibonacci Sequence
- Sum of first n terms of a harmonic progression
- "Look and say" sequence
- Is X a Fibonacci Matrix?
- Square Digits Number Chain Terminal Value (Inspired by Project Euler Problem 92)
- Golomb's self-describing sequence (based on Euler 341)
- Alternating sum
- Integer sequence - 2 : Kolakoski sequence
- Integer Sequence - II : New Fibonacci
Problem Recent Solvers40
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!