13
2
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" ]
Should the sort be stable? – Erik the Outgolfer – 2018-07-28T19:16:11.027
@EriktheOutgolfer All rolls are distinct and two rolls can always be sorted according to the ties rules. – Arnauld – 2018-07-28T19:20:46.587
Would it be OK to take each die as 0-5 instead of 1-6 (e.g.
012
instead of123
)? – wastl – 2018-07-28T20:38:00.677@wastl I'm going to say no. The format is flexible but the dice values must be in [1...6]. – Arnauld – 2018-07-28T20:52:11.173
You carry dice to the pub? – Beta Decay – 2018-07-29T00:54:44.387
@BetaDecay The dice rolling tray is made available by the bartender. This is not as popular as it used to be, though, and you'll only find that kind of games in a few establishments -- usually not the most sophisticated ones. – Arnauld – 2018-07-29T01:16:44.190