421 is a rather popular dice game in France and some other European countries. It is mostly played in bars and pubs to determine who's going to buy the next round of drinks. The full game is usually played in two rounds, with tokens that each player tries to get rid of, but this is irrelevant here. (Wikipedia page in French.)
The game is played with 3 standard cube dice.
Task
Your task is to sort a non-empty list of distinct 3-dice rolls [ X,Y,Z ] from highest to lowest, by applying the scoring rules of this game.
Basic scoring
- 4,2,1 is the highest possible combination. Depending on the rules, it may score 8, 10 or 11 points. Because we are sorting the rolls rather than counting the points, the exact value doesn't matter.
- Three Aces: 1,1,1 is the second highest combination and scores 7 points.
- Two-Aces: X,1,1 (where X is 2 to 6) scores X points.
- Three-of-a-Kind: X,X,X (where X is 2 to 6) scores X points.
- Straights: X,X+1,X+2 scores 2 points.
- All other rolls score 1 point.
Settling ties
Whenever two rolls give the same number of points, the following rules apply:
- A Two-Aces is better than a Three-of-a-Kind. Example: 5,1,1 beats 5,5,5.
- The Three-of-a-Kind 2,2,2 is better than a straight. Example: 2,2,2 beats 4,5,6.
- Straights are ordered from lowest to highest. Example: 4,5,6 beats 2,3,4.
- All other rolls are settled by sorting the dice from highest to lowest. Example: 6,5,2 beats 6,4,3. (Therefore, the lowest possible combination in the game is 2,2,1.)
Below are the 56 possible distinct rolls ordered from highest to lowest:
421 111 611 666 511 555 411 444 311 333 211 222 654 543 432 321
665 664 663 662 661 655 653 652 651 644 643 642 641 633 632 631
622 621 554 553 552 551 544 542 541 533 532 531 522 521 443 442
441 433 431 422 332 331 322 221
Challenge rules
- You may take the rolls in any reasonable format, such as a list of lists
[[3,2,1],[4,2,1]]
, a list of strings["321","421"]
, a list of integers[321,421]
, etc. However, each die must be clearly identifiable with a value from 1 to 6. - For each roll, you can assume that the dice are sorted either from lowest to highest or from highest to lowest, as long as it is consistent. Please state in your answer which order you're expecting, if any.
- The shortest answer in bytes wins!
Test cases
Using lists of strings with the dice sorted from highest to lowest:
Inputs
[ "321", "654" ]
[ "222", "321", "211" ]
[ "333", "311", "331", "111" ]
[ "111", "222", "333", "444" ]
[ "321", "421", "521", "621" ]
[ "422", "221", "442", "421", "222" ]
[ "222", "111", "421", "211", "651", "652", "543" ]
Expected outputs
[ "654", "321" ]
[ "211", "222", "321" ]
[ "111", "311", "333", "331" ]
[ "111", "444", "333", "222" ]
[ "421", "321", "621", "521" ]
[ "421", "222", "442", "422", "221" ]
[ "421", "111", "211", "222", "543", "652", "651" ]
012
instead of123
)? \$\endgroup\$