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*

Generate a deck of cards

Here's an array representing a standard deck of cards, including two Jokers.

[
 "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"
]

It's composed in this manner:

  • There are four suits; hearts, spades, diamonds, and clubs (H, S, D, C).
  • Each suit has one card for the numbers 2 to 10, plus 4 'picture' cards, Ace, Jack, Queen, and King (A, J, Q, K).
  • For each combination of suit and value, there should be one item in the array, which is a string, and is made up of the value followed by the suit (Whitespace between these is permitted).
  • On top of that, there are two Joker cards ('J').
  • Write in any language you please.
  • Golf it up! Try to produce this output in the smallest number of bytes.
  • It does not matter what order the output is in.

Answer*

Draft saved
Draft discarded
Cancel
6
  • \$\begingroup\$ Wouldn't [H.$t,S.$t,D.$t,C.$t] be shorter than explode? \$\endgroup\$ Commented Jun 12, 2018 at 11:00
  • \$\begingroup\$ You are absolutely right, gonna take your advise, thank you. \$\endgroup\$ Commented Jun 12, 2018 at 13:49
  • 1
    \$\begingroup\$ 73 bytes: Try it online! \$\endgroup\$ Commented Jul 22, 2018 at 9:56
  • 2
    \$\begingroup\$ @FranciscoHahn, sorry, I didn't notice that! Here is a 87 bytes version then: Try it online! \$\endgroup\$ Commented Jul 23, 2018 at 17:09
  • 1
    \$\begingroup\$ @Nigth2 i had no idea you can use array_push($arr, $item1,$item2,$item3...$itemN) like that, nice one \$\endgroup\$ Commented Jul 23, 2018 at 17:13

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