15
1
For the purposes of this question, a deck of cards is formatted in this way:
[
"AS", "2S", "3S", "4S", "5S", "6S", "7S", "8S", "9S", "10S", "JS", "QS", "KS",
"AD", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D", "10D", "JD", "QD", "KD",
"AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H", "10H", "JH", "QH", "KH",
"AC", "2C", "3C", "4C", "5C", "6C", "7C", "8C", "9C", "10C", "JC", "QC", "KC",
"J", "J"
]
Cards are always formatted as value, followed by suits. E.g. AS
is the Ace of Spades. The two single J's are Jokers. We want to shuffle this deck of cards, but the shuffle must be Superb™.
A Superb Shuffle™ is one in which:
- No two cards (except Jokers) of the same suit are adjacent.
- No card (except Jokers) is adjacent to one of the same value.
- No card (except Jokers) is adjacent to one of an adjacent value (one higher or one lower in this order, A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A. Notice that Ace can not be adjacent to either a 2 or a King).
- The Jokers can be in any position.
- The definition of a Superb Shuffle™ does not require the cards to be in a different order each time they are shuffled. Which isn't very superb, but it is Superb™.
Because that's Superb™.
An example might be:
[
"AS", "5D", "9H", "KC", "2D", "6H", "10C", "QS", "3H", "7C", "9S",
"KD", "4C", "6S", "10D", "AC", "3S", "7D", "JH", "J", "4D", "8H",
"QC", "AD", "5H", "9C", "JS", "2H", "6C", "8S", "QD", "3C", "5S",
"9D", "KH", "2S", "6D", "10H", "J", "3D", "7H", "JC", "KS", "4H",
"8C", "10S", "AH", "5C", "7S", "JD", "2C", "4S", "8D", "QH"
]
The challenge:
- Write some code to execute a superb shuffle
- Use any language.
- The input can be either:
- a deck of cards as described above in the same order, as an array or other list structure.
- No input (the code generates a deck of cards in that order)
- The output must be a full deck of cards in a Superb Shuffle™ as described above.
- Attempt to perform your Superb Shuffle™ in the smallest number of bytes.
- A link to an online interpreter such as Try It Online is preferred, but optional.
Happy shuffling!
1Somewhat related – Shaggy – 2018-06-18T11:24:01.473
Can we substitute
T
instead of10
? – Jo King – 2018-06-18T12:10:18.657@JoKing You may not. Just like the generating a deck of cards question, the different string lengths are part of the complexity. – AJFaraday – 2018-06-18T12:24:53.917
Are we allowed to print each card separately like the Charcoal answer does, or do we need to actually return an array/list? – Kevin Cruijssen – 2018-06-18T12:42:03.160
@KevinCruijssen That's fine, as long as it's noticably returning a deck of cards in that format (value then suit). – AJFaraday – 2018-06-18T12:43:09.983
Reminds me of this one
– The random guy – 2018-06-18T14:46:58.667@Therandomguy Yep, that's one of mine. There might be one or two more in the series, too ;) – AJFaraday – 2018-06-18T14:48:15.507
Would an array of arrays, each containing 3 or 4 cards be an acceptable output format? – Shaggy – 2018-06-18T15:58:09.907
In your penultimate bullet point, did you mean bytes instead of byes? – None – 2018-06-19T08:33:58.183
@paxdiablo Good use of the word "penultimate". Fixed it now. – AJFaraday – 2018-06-19T08:34:54.493
Can the jokers be next to each other? "Jokers in any position" but "No card is adjacent to one of the same value" – Sam Dean – 2018-06-19T10:46:30.970
Yes, they can. The Jokers are an exception. – AJFaraday – 2018-06-19T10:47:00.877
@SamDean Jokers don't have a value or a suit. – AJFaraday – 2018-06-19T10:47:18.977
@AJFaraday plenty of card games give it a value https://en.wikipedia.org/wiki/Joker_(playing_card)#Use_of_the_Joker_in_card_games
– Sam Dean – 2018-06-19T10:52:36.307@SamDean I'll just clarify my definition. – AJFaraday – 2018-06-19T10:53:40.690
Incidentally, this may not be the ideal shuffle for an actual game since if e.g. all aces are sufficiently non-adjacent then as you deal around a circle of players the same one might get them all ;) – Luke Sawczak – 2018-06-22T17:22:45.487
Who owns the trademark on Superb Shuffle? Curious to see ™ in an algorithm name. Never seen that before. – Todd Lehman – 2018-06-23T16:01:53.313