7th Sea dice

So there are a few extra things that can happen with 7th Sea dice, but the real sticking point is this: given n results, get as many discrete combinations of c as possible, where sum(c) >= k with the lowest remaining n.
Examples (k = 10):
Player rolls 7 dice. Results are [7, 5, 4, 3, 3, 2, 1]. [7, 3] = 10 [5, 3, 2] = 10 [4, 1] = 5 [4, 3, 3] = 10 [7, 2, 1] = 10 [5] = 5 Here, the second wins, because we have the fewest remaining results possible.
Player rolls 7 dice. Results are [9, 7, 5, 5, 2, 1, 1]. [9, 1] = 10 [7, 5] = 12 [5, 2, 1] = 8 [9, 1] = 10 [7, 2, 1] = 10 [5, 5] = 10 Here, the second is better because of more 10s.
Doing this as a human is pretty easy, but it's not so easy computationally. So, as @faraday asked for the challenge, here it is:
 Solve this in any language you want
 Avoid libraries that provide permutation/combination functionality
 Convert it to MU code

ZOMG that was hideous. The idea of converting this to MUSH code makes me want to cry, so I'll just leave this Ruby version here for anyone who cares. It optionally does the double raises and exploding 10s that you get at rank 4/5. It probably has bugs but worked decently enough on the modest number of tests I did.
This reminds me why I created a custom skill system (because most tabletop ones aren't designed with computers in mind).
Output:
============================= Rolling Dice ============================= Rolled [5, 10, 6, 5, 9, 10, 2, 9, 8, 6, 10] Exploding 3 dice Rolled [1, 2, 6] Final roll: [1, 2, 2, 5, 5, 6, 6, 6, 8, 9, 9, 10, 10, 10] ============================= Counting Combos Making 15 ============================= Found a combo! 10+5 Found a combo! 10+5 Found a combo! 9+6 0 groups of fives 6 raises so far ============================= Counting Junk Making 15 ============================= Junk dice: [10, 9, 8, 6, 6, 2, 2, 1] Adding up junk: [10, 1, 2, 2] Double Raise! Adding up junk: [9, 6] Double Raise! Adding up junk: [8, 6] 10 raises so far ============================= Counting Combos Making 10 ============================= Left over: [8, 6] 0 tens 0 groups of fives 10 raises so far ============================= Counting Junk Making 10 ============================= Junk dice: [8, 6] Adding up junk: [8, 6] Raise! 11 raises so far  11 Raises Total!
Edit: Fixed the link since Gist wasn't working the way I wanted.

In your comments:
# Example: Given junk dice of [6, 5, 3, 1, 1] it will return a sum of 11 (for the 6+1+1+3) and 'junk' will be the # unmatched [5] afterward.
Unless I misunderstood, I don't think this counts, since it's basically a cheat. 6+1+3 would get you 4, + 6 = 10. So you should have [1,5] for your junk dice, instead of just adding small to large.
[6, 5, 5, 3, 1, 1, 1]
shouldn't net6+1+1+1+3
and a5+5
with[ ]
junk. It should get6+3+1
,5+5
and junk of[1, 1]
. 
@Glitch I think you changed my example by adding an extra 5 and an extra 1?
[6, 5, 3, 1, 1]
nets 6+1+1+3 with a [5] left over, or 6+5 with a [3, 1, 1] left over, or 6+3+1 with a [1, 5] left over. I didn't see anything in the rules that specified which order you had to combine the dice in to reach 10. A human being would naturally see that the 6+3+1 goes together to make 10 neatly, but no matter which way you combine them you still only get 1 raise. Isn't that what matters?Also I think I wasn't clear on what I call "junk". Supposing we did have an extra dice in there for
[6, 5, 5, 3, 1, 1, 1]
. The only combo/pair is 5+5. The rest of the leftover stuff is what I called the junk. In your case: [6, 3, 1, 1, 1] . I freely admit the variable names are crappy  I really didn't have a lot of time to spend on it to make it clean. 
@faraday I did add extra dice, I'm sorry. In your example, though, I'm still not sure you're allowed to throw on extra dice after you've hit 10. Otherwise, what's to stop 6+5+3+1+1 and calling it a day? I feel like it's the same a saying 6+3+1 (10) +1.

@Glitch said:
I'm still not sure you're allowed to throw on extra dice after you've hit 10. Otherwise, what's to stop 6+5+3+1+1 and calling it a day? I feel like it's the same a saying 6+3+1 (10) +1.
The rules say: "Sometimes, you may use dice that add up to more than 10. Thatโs okay, itโs still a Raise." (Quickstart, p5, Step 4)
It doesn't really matter what dice are left over as far as I can tell. (Maybe there's a rule I missed?) The key is how many raises you can make. It's in your own best interests to make those raises efficiently  not wasting a die to "go over" when you could use it to make another raise. But if the extra 1 is going to be wasted either way, it doesn't seem to matter whether you make an 11 raise and have 1 die left over, or make a 10 raise and have two dice left over.
Edit to add: I know this is not the most accurate algorithm, but it was enough to satisfy my curiosity and make me run screaming from the idea of ever trying to automate this game system (although it looks fun to play on tabletop)

GMs can buy leftover dice, granting you a hero point and the GM as many danger points as you have remaining dice.

@Glitch said:
GMs can buy leftover dice, granting you a hero point and the GM as many danger points as you have remaining dice.
Ah I missed that. But still  given the "you can exceed 10" rule I cited, I don't see anything that prevents you from combining the dice any way you want to make a raise.
If you want to require them to make the "most efficient" combination of raises possible (i.e. with the most number of leftover dice) my gut tells me that you're going to have to iterate over all possible combinations. But maybe there's some advanced set theory algorithm out there  over my head, at any rate. I'm interested to see what others come up with.
At some point though I think you have to ask yourself  how faithful do you need to be to the mechanics. Usually when you adapt a preexisting game system to a computer game, compromises get made. As long as all players are subjected to the same algorithm, it's fair.

@faraday Why would there even be a mechanic for it, then? Otherwise, it'd just be floor(roll / 10). I think you need to iterate to get all combinations and that you're right it wasn't designed with computation in mind.

@Glitch said:
Why would there even be a mechanic for it, then? Otherwise, it'd just be floor(roll / 10).
Huh? I'm operating on the assumption that you still have to combine the dice. You can't just take your "8" die and split it into two 4's to turn [8, 7, 6] into two raises.
At any rate, I didn't realize that the leftover dice were relevant, so I didn't factor that into the algorithm. I was just looking to make 10's. Looking at the mechanics again  yeah, I have to agree that a tabletop GM wouldn't accept 6+3+1+1 as a valid raise because it denies them the opportunity to snag that extra "1" die as a danger thing. If you wanted to use that mechanic on your MUSH (I wouldn't, personally), this algorithm wouldn't work.
Amusing diversion though.


For you.


@Lithium describes the reason why I stopped trying to logic it out with Mushcode. The best answer for players is not logical to the stated rules. A roll can be minmaxed.
Really, the "keep" system was a lot more straightforward.

@Lithium said:
If left over dice are bad, why wouldn't it make a raise out of 5, 3, 1, and 1 with 6 left over?
I wasn't trying to min/max the number of dice left over, but merely to make the combination of dice legit. 6+3+1+1 was not legit. Your dice can exceed 10 (6+5, for instance) but you can't hit 10 with 6+3+1 and then just keep chucking additional dice on it.
Whether you do 6+3+1 or 5+3+1+1, though, seems largely to be a matter of personal preference. Leftover dice are a twoedged sword. The GM gets danger points, but you get hero points.
I'm with @Thenomain though  this system sounds fairly annoying and needlessly complicated even in tabletop. In a MUSH, it's insanity. If I were going to do a 7th Sea game on a MUSH, I would just take SumOfDice/10 and be done with it.

@faraday said:
If I were going to do a 7th Sea game on a MUSH, I would just take SumOfDice/10 and be done with it.
I'm planning on showing the results and saying "enjoy!"
"5 3 1 1" + "6" is legit, and is better for the rolling player. Then again, I don't think the game is designed about worrying this much. If you get 2 Hero Points for having "5 1" left over, then that's something you get for overcoming more potential danger. Both the ST and the players seem to be on the same side, as instructed by the rules: Let the players be awesome in the face of adversity.

Just some clarification, you get a single hero point if the GM decides to purchase the remaining dice (no matter how many there are) and the GM gets danger points equal to the remaining dice.

@Glitch said:
Just some clarification, you get a single hero point if the GM decides to purchase the remaining dice (no matter how many there are) and the GM gets danger points equal to the remaining dice.
The number of remaining dice and not its total, to be even clearer. My brain keeps coming up with minmax bullshittery: It's better to pick "6 2 1 1" + "2" than "6 2 2" + "1 1"? Why? What fun is this at all?
I don't think it brings anything to the game. While I'm tempted to agree to "total / 10" (remainder = there are remainder dice), I'd like to see if "pick 10s as usual, 1 hero point and 1 villain point for any number of leftover dice" is enough to make this less aggravating.
edit: I thought of a potential for why a situation would be to bring more villain points to the ST, if it's rarer for them to get these points and therefore harder to challenge the players.

@Thenomain said:
edit: I thought of a potential for why a situation would be to bring more villain points to the ST, if it's rarer for them to get these points and therefore harder to challenge the players.
Relying on completely random chance, or the player's inability to min/max their dice sums is a silly way to bring challenge to a game IMHO.

A game that relies on an ability to minmax for simple roll resolution is also silly. Also, "silly" is being kind.
We may be being a hint too hard on it, as well; counting to '10' and sometimes '15' isn't hard, it's all the rare but notable occasions where one way to count is superior to another. I am deeply conflicted.