I don't think you have a complete statement of the problem. Why, in the first example, are arrangements like 1 1 2 excluded? And you only accept the arrangements in a particular order. How do you define the order?
the data ascended by column,when the first column is the same, sort by the second column,...
Thanks - and I realize now that 1 1 2 is not excluded; I just wasn't looking carefully.
The best way to generate such a sequence is using depth-first search or recursion. By prohibiting the usage of IFs, all solutions are inefficient (because we can't cut the tree, and are forced to follow all branches).
For the 3 balls 2 boxes cases, shouldn't the following be part of the answer as well?
1 2 1
2 1 1
2 1 2
2 2 1
Number of 1s in the Binary Representation of a Number
Make one big string out of two smaller strings
Back to basics 26 - Keywords
Find number of days
Are all the three given point in the same line?
Successive zeros (harder)
Return fibonacci sequence do not use loop and condition version 2
Project Euler: Problem 14 Longest Collatz sequence(harder version)
Find the maximum two numbers of every column of a matrix
Compute the intersect point of line and plan
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office