A Quick Ruby Kata
This is, I have on good authority, actual homework from a 4th grade gifted program, paraphrased to make it more code-kata like.
Find all the unique sequences of digits, like [1, 1, 2, 3, 8] that have the following properties:
-
Each element of the sequence is a digit between 1 and 9
-
The digits add to 15
-
There is at least digit that appears exactly twice
-
No digit appears more than twice
-
Order is irrelevant [1, 1, 2, 3, 8] and [1, 3, 2, 1, 8] are the same sequence and only count once.
I believe the original problem did specify that there are 38 sequences that match.
I’m interested in seeing solutions to this if anybody goes ahead and does it. I’m pretty sure there’s an elegant solution using Ruby 1.9 enumerations, but that’s not the way I went on my first try.