8
According to this question a Superb Shuffle™️ is defined as a full deck of cards (including jokers) which follows this set of rules:
- 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 cards are expressed as a value(A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K), followed by a suit (C, D, H, S). For example 'AS' is the Ace of Spades. The Jokers are represented by a single letter J.
- Write some code to indicate if an array of cards is a Superb Shuffle™️ or not.
- Use any language you like.
- Attempt to do so in the smallest number of bytes.
Test cases:
1: This is Superb™️
[
"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"
]
# true
2: This is all sorted
[
"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"
]
# false
3: Aces together
[
"AC", "AS", "AD", "AH", "5D", "9H", "KC", "2D", "6H", "10C", "QS",
"9S", "KD", "4C", "6S", "10D", "3S", "7D", "JH", "J", "4D", "8H",
"QC", "5H", "9C", "JS", "2H", "6C", "8S", "QD", "3C", "5S", "3H",
"9D", "KH", "2S", "6D", "10H", "J", "3D", "7H", "JC", "KS", "4H",
"8C", "10S", "5C", "7S", "JD", "2C", "4S", "8D", "7C", "QH"
]
# false
4: Crazy 8's
[
"AS", "5D", "9H", "KC", "2D", "6H", "10C", "QS", "3H", "7C", "9S",
"KD", "4C", "6S", "10D", "AC", "3S", "7D", "JH", "J", "4D", "AH",
"QC", "AD", "5H", "9C", "JS", "2H", "6C", "QD", "3C", "5S", "10S",
"9D", "KH", "2S", "6D", "10H", "J", "3D", "7H", "JC", "KS", "4H",
"5C", "7S", "JD", "2C", "4S","QH", "8D", "8S", "8C", "8H"
]
# false
5: Also superb
[
"AS", "6H", "9S", "AC", "4D", "9C", "QD", "2S", "7H", "10S", "2C",
"5D", "10C", "KD", "3S", "8H", "JS", "3C", "6D", "JC", "AH", "4S",
"9H", "QS", "4C", "7D", "QC", "2H", "5S", "10H", "KS", "5C", "8D",
"KC", "3H", "6S", "JH", "AD", "6C", "9D", "J", "4H", "7S", "QH",
"2D", "7C", "10D", "J", "5H", "8S", "KH", "3D", "8C", "JD"
]
# true
6: Ace by 2
[
"AS", "2S", "6H", "9S", "AC", "4D", "9C", "QD", "7H", "10S", "2C",
"5D", "10C", "KD", "3S", "8H", "JS", "3C", "6D", "JC", "AH", "4S",
"9H", "QS", "4C", "7D", "QC", "2H", "5S", "10H", "KS", "5C", "8D",
"KC", "3H", "6S", "JH", "AD", "6C", "9D", "J", "4H", "7S", "QH",
"2D", "7C", "10D", "J", "5H", "8S", "KH", "3D", "8C", "JD"
]
# false
7: Ace by King
[
"AS", "KH", "2S", "6H", "9S", "AC", "4D", "9C", "QD", "7H", "10S",
"2C", "5D", "10C", "KD", "3S", "8H", "JS", "3C", "6D", "JC", "AH",
"4S", "9H", "QS", "4C", "7D", "QC", "2H", "5S", "10H", "KS", "5C",
"8D", "KC", "3H", "6S", "JH", "AD", "6C", "9D", "J", "4H", "7S",
"QH", "2D", "7C", "10D", "J", "5H", "8S", "3D", "8C", "JD"
]
# false
8: Jokers together
[
"AS", "5D", "9H", "KC", "2D", "6H", "10C", "QS", "3H", "7C", "9S",
"KD", "4C", "6S", "10D", "AC", "3S", "7D", "JH", "J", "J", "4D",
"8H", "QC", "AD", "5H", "9C", "JS", "2H", "6C", "8S", "QD", "3C",
"5S", "9D", "KH", "2S", "6D", "10H", "3D", "7H", "JC", "KS", "4H",
"8C", "10S", "AH", "5C", "7S", "JD", "2C", "4S", "8D", "QH"
]
# true
9: Adjacent suit/value separated by Jokers
[
"AS", "6H", "9S", "AC", "4D", "J", "4H", "2S", "7H", "10S", "2C",
"5D", "10C", "KD", "3S", "8H", "JS", "3C", "6D", "JC", "AH", "4S",
"9H", "QS", "4C", "7D", "QC", "2H", "5S", "10H", "KS", "5C", "8D",
"KC", "3H", "6S", "JH", "AD", "6C", "9D", "J", "QD", "7S", "QH",
"2D", "7C", "10D", "8C", "5H", "8S", "KH", "3D", "9C", "JD"
]
# true
2”If any of the cards are missing, that is not a Superb Shuffle" - Boo-urns to input validation! – Shaggy – 2018-06-22T08:01:32.030
I personally agree with @Arnauld and Shaggy. A challenge validating these two things of a shuffled 54-cards deck: 1. No adjacents of the same suit. 2. No adjacents of the same, one lower, or one higher values seems like a good challenge. If we should also validate: Are there exactly 54 cards (not too few or too many); are all cards in the correct format; are there no weird ASCII inputs; are there no empty strings; are there no duplicated cards; etc. etc. seems a overkill to me personally. – Kevin Cruijssen – 2018-06-22T08:10:10.343
@KevinCruijssen I missed that one – AJFaraday – 2018-06-22T08:30:56.397
2Sequences such as
4D, J, 3D
orJ, JS
may also result in false negatives. – Arnauld – 2018-06-22T09:36:23.693@Arnauld Ah, shit.. Had a solution that I was about to post, but it indeed fails for
4D, J, 3D
.. – Kevin Cruijssen – 2018-06-22T09:40:04.743The TIO link of my Java answer contains some suggested test cases. Two truthy: one with
4D,J,4H
and9D,J,QD
(same value or suit with Joker in between); and one withJ,J
(two adjacent Jokers). And two falsey: one withAS,2D
and one withAS,KC
(to test if Ace is both adjacent to 2s and Kings). (Already tested the existing Ruby and JS answers, and they are working correctly for these test cases.) – Kevin Cruijssen – 2018-06-22T12:01:48.993@AdmBorkBork Thanks for letting me know – AJFaraday – 2018-06-22T12:29:43.400
@KevinCruijssen I've added them, thanks. – AJFaraday – 2018-06-22T12:29:53.117
I prefer to deal with a Superb Owl. (stupid joke primarily in the USA) – Carl Witthoft – 2018-06-22T17:25:21.590
@CarlWitthoft I like to think that a Superb Owl would be able to produce a Superb Shuffle. – AJFaraday – 2018-06-22T17:32:08.433
I'm not clear on what's actually guaranteed of the input. Is it always a permutation of the correct 54 cards? – xnor – 2018-06-23T04:05:49.183
@xnor that is the assumption, yes. I initially made validation of that part of the challenge, but there were some strong objections to that. – AJFaraday – 2018-06-23T07:03:27.253