Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Execute a Superb ShuffleTM

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 SuperbTM.

A Superb ShuffleTM 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 ShuffleTM does not require the cards to be in a different order each time they are shuffled. Which isn't very superb, but it is SuperbTM.

Because that's SuperbTM.

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 ShuffleTM as described above.
  • Attempt to perform your Superb ShuffleTM in the smallest number of bytes.
  • A link to an online interpreter such as Try It Online is preferred, but optional.

Happy shuffling!

Answer*

Draft saved
Draft discarded
Cancel
1
  • 1
    \$\begingroup\$ ā17*è should save 2 more bytes \$\endgroup\$ Commented Jun 18, 2018 at 12:56

AltStyle によって変換されたページ (->オリジナル) /