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.
• @KevinCruijssen that’s correct. The initial question specifies the numbers 2 to 10, and an array of strings as an output. Jun 11 '18 at 9:26
• I was just wondering if you could get 23456789 by multiplying 2 smaller numbers... only to discover it's prime! Jun 11 '18 at 11:57
• @match Since the order of the output doesn't matter, maybe you can still create it with smaller numbers by ending it with 2 or 4 or anything else so it isn't a prime anymore. Jun 11 '18 at 13:19
• Rules in comments don't count. If we cannot print the result to STDOUT (and that's a big if, as it overrides our defaults for I/O and prevents languages without functions and string arrays from participating), that rule has to be stated explicitly in the challenge spec. Jun 12 '18 at 15:05
• That doesn't rule out a string representation of such an array, which could be printed to STDOUT. If not for the comment section, I never would have guessed this wasn't allowed. Jun 12 '18 at 23:50

JavaScript (ES6), 62 60 bytes

f=n=>n>51?'JJ':[('JQKA'[k=n>>2]||k-2)+'CDHS'[n&3],...f(-~n)]


Try it online!

• Smooth moves!!! Jun 11 '18 at 14:46
• I didn't know spread syntax existed until I read this -- very cool Jun 15 '18 at 17:29

Bash43 34 bytes

d=({A,J,Q,K,{2..10}}{H,S,D,C} J J)


Try it online!

• 9 bytes shorter Jun 11 '18 at 17:34
• I did not think braces were nestable. Thanks. Jun 11 '18 at 17:53
• And here I was thinking "what language do I know that conveniently does direct products on lists of strings?" I didn't even think about good old glob! Jun 13 '18 at 1:21
• Technically brace expansion is not a glob pattern, it is its own special syntax Jun 14 '18 at 3:19

brainfuck, 200 197 bytes

+[[<+>->++<]>]+<++++<<+++[->+++>+++++>+>+<<<<]>+.<<.>>.--<<<[->>+++<<]>>+>[<<.>.-.+>.<<.<<[>>>+.>.<<.<+<-]>[-<+>>>+<<]>>.>.<<.>+++++++++.>.<<.>+.>.<<.>++++++.>.,++++[-<-------->]>[[-<+>]>]<<[<]>>>]


Try it online!

Uses one negative cell (+1 bytes to fix), wrapping cells (lots o' bytes to fix) and 0 on EOF (+2 bytes to remove dependancy).

Outputs

J J 10H 2H 3H 4H 5H 6H 7H 8H 9H AH JH KH QH 10S 2S 3S 4S 5S 6S 7S 8S 9S AS JS KS QS 10D 2D 3D 4D 5D 6D 7D 8D 9D AD JD KD QD 10C 2C 3C 4C 5C 6C 7C 8C 9C AC JC KC QC


Explanation:

+[[<+>->++<]>]  Sets the tape to powers of 2
TAPE: 1 2 4 8 16 32 64 128 0 0'
+<++++<<+++[->+++>+++++>+>+<<<<]   Uses the 64 and the 128 to generate the suit letters
TAPE: 1 2 4 8 16 32 0' 73 83 68 67
I  S  D  C
>+.<<.>>.--<<     Prints the Jokers
<[->>+++<<]>>+>   Uses the 16 to create 49
TAPE: 1 2 4 8 0 32 49 72' 83 68 67
H   S  D  C
[  Loop over the suits
<<.>.-.+>.<<.<<      Print the 10 card with a leading space
TAPE: 1 2 4 8' 0 32 49 Suit
[>>>+.>.<<.<+<-]  Use the 8 to print the other 8 number cards
TAPE: 1 2 4 0' 8 32 57 Suit
>[-<+>>>+<<]      Move the 8 back into place while also adding it to the 57
TAPE: 1 2 4 8 0' 32 65 Suit

>>.>.<<.         Print the Ace
>+++++++++.>.<<. Print the Jack
>+.>.<<.         Print the King
>++++++.>.<<.    Print the Queen
TAPE: 1 2 4 8 0 32 81' Suit
>>,    Clear the current suit
++++[-<-------->]    Subtract 32 to get back to 49 (reusing the space is longer than just subtracting 32)
TAPE: 1 2 4 8 0 32 49 0' MoreSuits?
>[[-<+>]>]<<[<]>>>   Shift all the remaining suits over one
TAPE: 1 2 4 8 0 32 49 Suit?'
] End on the character of the next suit and repeat

• That more than 2.5 time shorter than my solution. Well done. Jun 12 '18 at 14:52

05AB1E, 28272524 23 bytes

2TŸ.•-Ÿ•S«.•ôì•âJ„jjS«u


Try it online.

-1 byte thanks to @Emigna removing the S after "HSDC", because â does this implicitly.

Explanation:

2TŸ           # Push list in the range [2,10]: [2,3,4,5,6,7,8,9,10]
.•-Ÿ•      # Push compressed string "ajqk"
S     # Convert it to a list of characters: ["a","j","q","k"]
«    # Merge the two lists together: [2,3,4,5,6,7,8,9,10,"a","j","q","k"]
.•ôì•         # Push compressed string "cdhs"
â             # Cartesian product of each (pair each character of both lists):
#  [[2,"a"],[2,"d"],[2,"h"],...,["k","d"],["k","h"],["k","s"]]
J             # Join each pair together to a single string:
#  ["2a","2d","2h",...,"kd","kh","ks"]
„jjS          # Push string "jj", and convert it to a list of characters: ["j","j"]
«         # Merge both lists together:
#  ["2a","2d","2h",...,"kd","kh","ks","j","j"]
u        # Convert everything to uppercase:
#  ["2A","2D","2H",...,"KD","KH","KS","J","J"]
# (and output the result implicitly)


See this 05AB1E tip of mine (section How to compress strings not part of the dictionary?) to understand why .•-Ÿ• is "ajqk" and .•ôì• is "cdhs".

brainfuck, 550 504 bytes

++++++++++[>+++>+++++>+++++++<<<-]>++>->[>+>+>+>+<<<<-]>----->++++.<<<<.>>>>.<<<<.>>>>>--->+++++++++++++<<<<<.-.+>>>>.<<<<<.>.-.+>>>>+.<<<<<.>.-.+>>>>++++.-----<<<<<.>.-.+>>>>>.<<<<<<.>>++++++++[-<+.>>>>.<<<<<.>.>>>>+.<<<<<.>.>>>>++++.-----<<<<<.>.>>>>>.<<<<<<.>>]>.>>.<<<<<.>>>>.>.<<<<<.>>>>+.>.<<<<<.>>>>++++++.>.<<<<<.>>>.>>+.<<<<<.>>>>.>.<<<<<.>>>>------.>.<<<<<.>>>>-.>.<<<<<.>>>.>>++++.<<<<<.>>>>.>.<<<<<.>>>>+.>.<<<<<.>>>>++++++.>.<<<<<.>>>.>>>.<<<<<<.>>>>.>>.<<<<<<.>>>>------.>>.<<<<<<.>>>>-.>>.


Try it online!

Java 10, 15315112577 75 bytes

v->("AJQK2345678910".replaceAll("1?.","$0H,$0S,$0D,$0C,")+"J,J").split(",")


-28 bytes thanks to @OlivierGrégoire.
-50 bytes thanks to @mazzy.

Try it online.

Explanation:

v->                      // Method with empty unused parameter and String-array return-type
"AJQK2345678910"
.replaceAll("1?.",    //  Replace every loose character (or "10" as single char)
"$0H,$0S,$0D,$0C,") //  with "cH,cS,cD,cC,", where c is the character
+"J,J")               //  Append "J,J"
.split(",")            //  And split everything by commas

• Jun 11 '18 at 10:13
• try "AJQK2345678910".replace("1?.","$0H,$0S,$0D,$0C,")+"J,J" and split it. Jun 11 '18 at 11:51
• Smart @mazzy Thanks. And was already editing it, Olivier. :) Jun 11 '18 at 12:02
• cool! I believe it is possible to remove 2 bytes more - brackets in the pattern. see regex101.com/r/aDbz9C/1 Jun 11 '18 at 12:35
• @mazzy Oh, didn't even knew $0 was possible in Java. TIL, thanks. :) Jun 11 '18 at 12:54 APL (Dyalog Unicode), 29 bytes 1 byte saved thanks to Probie by using 1+⍳9 instead of 1↓⍳10 'JJ',,'HCDS'∘.,⍨'AKJQ',⍕¨1+⍳9  Try it online! This is a full program. In the TIO link, I have enabled boxing so that the individual elements of the array can be distinguished. Here is the boxed output. ┌─┬─┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬───┬───┬───┬───┐ │J│J│AH│AC│AD│AS│KH│KC│KD│KS│JH│JC│JD│JS│QH│QC│QD│QS│2H│2C│2D│2S│3H│3C│3D│3S│4H│4C│4D│4S│5H│5C│5D│5S│6H│6C│6D│6S│7H│7C│7D│7S│8H│8C│8D│8S│9H│9C│9D│9S│10H│10C│10D│10S│ └─┴─┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴───┴───┴───┴───┘  'JJ', 2 jokers concatenated to , the raveled form of ∘.,⍨ the matrix created by concatenating every combination of • 'HCDS' this string against • 'AKJQ', this string with • ⍕¨ the stringified forms of each of • 1+⍳9 the numbers 2..10 (1 plus the range 1..9) • I've changed the indentation of your list in the explanation. It looked a bit weird with the two and three dots.. If that was intended for some reason, feel free to rollback. Jun 11 '18 at 11:31 • @KevinCruijssen Thanks, I couldn't figure out how to do that, so I used multiple bullet points hah Jun 11 '18 at 11:39 • Yeah, I thought so, that's why I changed it. :) You need multiples of four leading spaces before the - to indent it. Jun 11 '18 at 11:51 Befunge-98 (FBBI), 75 bytes j4d*1-2k:d%4+1g:'0-!#v_>,d/1g,' ,!#v_3 CHSDA234567890JQK@;1'< ^,;,k2"J J" <  Try it online! Program structure At first, the stack is filled with 0's, and j does not jump over the initialisation. The initialisation pushes 4 * 13 = 52, which is the program counter. In the following iterations the trailing 3 causes the pointer to jump over this part. 1-2k:d%4+1g,d/1g,' ,!#v_ Main loop 1- decrement counter 2k: duplicate counter three times d% counter mod 13 ... 4+ ... + 4 is the position of the card in the Data section 1g, get the card from row 1 and print it d/ counter / 13 is the position of the suit in the Data section 1g, get the suit from row 1 and print it ' , print a space as seperator ! negate the counter (0 for non-zero, 1 for 0) _ If the counter is 0, move West ... #v ... and move to the termination otherwise, continue with the next iteration  Code that prints 10: '0-!#v_> Checks if Card is '0' '0- subtract the '0' from the card ! negate (1 for '0', 0 for all other cards) _ If card was '0', move West #v and go South to print '10' Else continue to go East ;1'< ^,; Prints '10' < Go West 1' Push '1' ; Jump to ... ; ... the next semicolon , Print '1' ^ Go back to the main loop The '0' will be printed by the main loop  Termination: @; ... ;,k2"J J" < < Go West "J J" Push "J J" ,k2 Print it ; Jump to ... ; ... the next semicolon @ terminate the program  R, 65 bytes c(outer(c('A',2:10,J<-'J','Q','K'),c('S','D','H','C'),paste),J,J)  Try it online! -2 Bytes thanks to @Giuseppe and @JayCe suggestions • This was my exact answer, although I think I used double quotes instead of single quotes. Jun 11 '18 at 12:44 • Sorry, have I double-posted your answer ? I checked but I couldn't find any R answer... Jun 11 '18 at 13:14 • Oh no I had just typed it all up myself in TIO before seeing yours :-) Jun 11 '18 at 13:26 • Yes outer is definitely the way to go here! Although whitespace is premitted as per spec so you can save one byte by using paste. @Giuseppe too. Jun 11 '18 at 15:00 • I pointed this out on JayCe's answer, but you can set x<-'J' inside the outer and then re-use x as a variable in the outermost c() statement to shave off a byte: Try it online! Jun 11 '18 at 18:03 Powershell, 636159 56 bytes -3 bytes: thanks ConnorLSW 2..10+'AJQK'[0..3]|%{"$_H";"$_S";"$_D";"$_C"};,'J'*2  • -3 using string to array for the first part : 2..10+'AJQK'[0..4]|%{"$_H";"$_S";"$_D";"$_C"};,'J'*2 Jun 11 '18 at 14:43 • cool! any idea how to remove ? Jun 11 '18 at 14:57 • as far as I know that's the cheapest way to break up a variable in a string, I took a look at a loop but it's more expensive by 2 chars to do it that way. Jun 11 '18 at 14:59 Perl 5, 41 bytes sub{J,J,map<"$_"{S,D,H,C}>,A,2..10,J,Q,K}


Try it online!

• This has taught me something really interesting about globbing. Nice. Jun 12 '18 at 23:33

Python 3, 67 64 bytes

print(*[a+b for a in['10',*'A23456789JQK']for b in'CHSD'],*'JJ')


Try it online!

Python 2, 787674 68 bytes

print['1'*(a<'1')+a+b for a in'A234567890JQK'for b in'CHSD']+['J']*2


Try it online!

Alt:

Python 2, 68 bytes

print[a+b for a in['10']+list('A23456789JQK')for b in'CHSD']+['J']*2

print['1'[a>'0':]+a+b for a in'A234567890JQK'for b in'CHSD']+['J']*2


saved

• -3 bytes, thanks to ovs
• That's a pretty thorough answer... Jun 11 '18 at 9:15
• 64 bytes
– ovs
Jun 11 '18 at 11:07
• If we don't have to use print, can't we do [*[a+b for a in['10',*'A23456789JQK']for b in'CHSD'],*'JJ'] in 59 bytes. The Haskell solution doesn't need to output to stdout, why would Python? Jul 4 '18 at 2:38

K (ngn/k), 30 bytes

"JJ",/("AKQJ",$2+!9),'/:"SHDC"  Try it online! !9 is the list 0 1 ... 8 2+!9 is the list 2 3 ... 10 $ to string

, concatenate

,'/: concatenate each with each right, i.e. Cartesian product; normally it's ,/:\: or ,\:/: but on the right we have only scalars ("SHDC"), so we can use ' instead of \:

"JJ",/ join (concat reduce) the list on the right using "JJ" as initial value for the reduction

MS-SQL, 137 bytes

SELECT v.value+s.value
FROM STRING_SPLIT('A-2-3-4-5-6-7-8-9-10-J-Q-K','-')v,STRING_SPLIT('H-S-D-C--','-')s
WHERE s.value>''OR v.value='J'


An array of values in SQL is returned as separate query rows. Uses the STRING_SPLIT function introduced in SQL 2016.

It includes the jokers by adding two "blank string" suits to take advantage of the existing "J" for Jack, then filtering out rows we don't want. Shorter than using UNION ALL statements to add the jokers.

• What happens if you make the second argument for STRING_SPLIT an empty string? I don’t use MS-SQL, but in many languages it would give you all the characters in an array. Jun 12 '18 at 7:15
• @AJFaraday That would be handy, but it doesn't work, you get Procedure expects parameter 'separator' of type 'nchar(1)/nvarchar(1)'. It would also be handy for golfing if it defaulted to a comma if you left out the second parameter, but it doesn't support that either. Another item for the GolfSQL language I'll probably never get around to writing :) Jun 12 '18 at 13:29

Ruby, 61 bytes

->{[*0..52,52].map{|x|['JAKQ'[w=x%13]||w-2,'SDHC'[x/13]]*''}}


Try it online!

• That's some skill to use the J for both Jack and Joker :-) Jun 14 '18 at 15:37
• Can't you save 4 bytes by leaving out the ->{...}? It runs on its own and doesn't need parameters, so it shouldn't need to be a lambda Aug 10 '18 at 1:27

C# .NET, 114 bytes

o=>(new System.Text.RegularExpressions.Regex("1?.").Replace("AJQK2345678910","$0H,$0S,$0D,$0C,")+"J,J").Split(',')


Try it online.

Interesting alternative of 119 bytes by @Corak.

using System.Linq;o=>new[]{"J","J"}.Concat(from s in"SDCH"from n in"A234567890JQK"select(n=='0'?"10":n+"")+s).ToArray()


Try it online.

If an System.Collections.Generic.IEnumerable<string> instead of string[] is an acceptable output, the trailing .ToArray() can be dropped so it becomes 109 bytes.

Explanation:

using System.Linq;       // Required import for the from .. in .. and select parts
o=>                      // Method with empty unused parameter and string-array return-type
new[]{"J","J"}         //  Return a string-array containing two times "J"
from s in"SDCH"     //   Loop over the suits
from n in"A234567890JQK"
//    Inner loop over the cards
select(n=='0'?  //     If the current card item is '0'
:        //     Else:
n+"")   //      Simply use the card item as is
+s)//     And append the suit
.ToArray()            //  Convert the IEnumerable to an array


PHP, 10899 97 Bytes

Try it online!

Try it online! (Edit 1)

Code

<?php $r=[J,J];foreach([A,J,Q,K,2,3,4,5,6,7,8,9,10]as$t)
$r=array_merge($r,[H.$t,S.$t,D.$t,C.$t]);


Tried to use purely php funcions, but bytecount was lower with a loop :(

Output (using print_r)

Array
(
[0] => J
[1] => J
[2] => HA
[3] => SA
[4] => DA
[5] => CA
[6] => HJ
[7] => SJ
[8] => DJ
[9] => CJ
[10] => HQ
[11] => SQ
[12] => DQ
[13] => CQ
[14] => HK
[15] => SK
[16] => DK
[17] => CK
[18] => H2
[19] => S2
[20] => D2
[21] => C2
[22] => H3
[23] => S3
[24] => D3
[25] => C3
[26] => H4
[27] => S4
[28] => D4
[29] => C4
[30] => H5
[31] => S5
[32] => D5
[33] => C5
[34] => H6
[35] => S6
[36] => D6
[37] => C6
[38] => H7
[39] => S7
[40] => D7
[41] => C7
[42] => H8
[43] => S8
[44] => D8
[45] => C8
[46] => H9
[47] => S9
[48] => D9
[49] => C9
[50] => H10
[51] => S10
[52] => D10
[53] => C10
)


Edit

Thanks to @JoKing by suggesting change explode(" ","H$t S$t D$t C$t") for [H.$t,S.$t,D.$t,C.$t]

• Wouldn't [H.$t,S.$t,D.$t,C.$t] be shorter than explode?
– Jo King
Jun 12 '18 at 11:00
• You are absolutely right, gonna take your advise, thank you. Jun 12 '18 at 13:49
• 73 bytes: Try it online! Jul 22 '18 at 9:56
• @FranciscoHahn, sorry, I didn't notice that! Here is a 87 bytes version then: Try it online! Jul 23 '18 at 17:09

Japt, 3230 26 bytes

'J²¬c"JQKA"¬c9õÄ)ï+"CHSD"q


Test it

'J²¬c"JQKA"¬c9õÄ)ï+"CHSD"q
'J                             :Literal "J"
²                            :Repeat twice
¬                           :Split
c                          :Concatenate
"JQKA"¬                   :  Split "JQKA"
c                  :  Concatenate
9õ                :    Range [1,9]
Ä               :    Add 1 to each
)              :  End concatenation
ï             :  Cartesian Product
"CHSD"q     :    Split "CHSD"
+            :  Join each pair to a string


Batch, 118 bytes

@for %%s in (C D H S)do @(for /l %%r in (2,1,10)do @echo %%r%%s)&for %%r in (J Q K A)do @echo %%r%%s
@echo J
@echo J


J, 41 bytes

'J';^:2,'HCDS',&.>/~(":&.>2+i.9),;/'AJQK'


Try it online!

• 'J';^:2,;&.>{_13<\'10';;/'23456789AJKQHCDS' slightly simpler but for 43. I feel like there's more to shave here... but I can't see how. Jun 12 '18 at 5:26
• @Jonah Yes, I also tried something similar and I'm sure my solution can be golfed further, but there are always new problems to be solved :) Jun 12 '18 at 6:27

R, 67 66 bytes

c(paste(rep(c('A',2:10,J<-'J','Q','K'),4),c('S','D','H','C')),J,J)


Try it online!

Only one more byte than digEmAll's golfier solution. Inspired byGiuseppe's solution to this related challenge - the same Giuseppe who golfed one byte off by answer!

I'm posting separately since it's a slightly different approach taking advantage of the fact that 4 is not a divisor of 13 and that the output does not need to be in any particular order.

• oh haha I didn't notice this, I commented this solution on the other one Jun 11 '18 at 16:48
• @Giuseppe I was very close to comment instead of posting myself. I guess I just couldn't resist the urge to answer :) Jun 11 '18 at 17:35
• iiiit's just as golfy as digemall's answer :-) try it online Jun 11 '18 at 17:44
• @I was just experimenting with that :) so both digemall and I can golf one byte thanks to you :) Jun 11 '18 at 17:47

C (gcc), 126137 133 bytes

#define S(X)"A"X,"2"X,"3"X,"4"X,"5"X,"6"X,"7"X,"8"X,"9"X,"10"X,"J"X,"Q"X,"K"X,
#define c (char*[54]){S("S")S("D")S("H")S("C")"J","J"}


Try it online!

+11 bytes to be more complete thanks to Jakob.

-4 bytes thanks to Zachary

Mostly abusing of preprocessor to compress the suits. Could probably be out-golfed, but is pretty efficient all things considered.

• I would argue that c is not a "[...] weird 'function' [...]" but rather an array declaration stored in a macro. Such a form of output is to my knowledge not permitted by default. Jun 11 '18 at 15:19
• Except c is not an array, it would be an in-place literal. Each 'invokation' of c in the source will create a new copy of the array in the resulting executable (barring optimizations). Thus, the code char *a[] = c; char *b[] = c; create two deep copies of c. This behaviour is what you'd expect of a function as well. Jun 11 '18 at 15:21
• If there was a challenge to output the integer zero, would you consider the C code c=0; a valid submission, viewing c as a function? Jun 11 '18 at 15:34
• no, but I would consider #define z 0 valid. The reasoning is that: c=0; c++; x=c; results in x == 1 so c doesn't act much like a function. Meanwhile #define z 0 c=z; c++; x=z; does result in x == 0 so z acts like a function. Jun 11 '18 at 15:36
• I do not think that is a fair comparision as you first change the supposed function, then only change the supposed function's return value. z=0;/**/c=z;c++;x=z; results in x==0, thus z acts like a function. Jun 11 '18 at 15:41

Javascript (ES6) 7774 72 bytes

This is a complete program.

J,J,${[..."A23456789JQK",10].map(c=>[..."SDHC"].map(s=>c+s))}.split,  • Nice. You can save a few bytes by splitting on commas instead of concatenating: BTJ,J,${[..."A23456789JQK","10"].map(c=>[..."SDHC"].map(s=>c+s))}BT.splitBT,BT (where BT is a backtick). Jun 11 '18 at 17:19
• Awesome suggestion! Thanks. Jun 11 '18 at 17:20

C (gcc, clang), 138 bytes

#define p(c)putchar(c)
int main(){for(char*q,*r="CDHS";*r;r++)for(q="A234567890JQK";*q;q++)(48==*q)&&p(49),p(*q),p(*r),p(32);puts("J J");}


Approach is to encode the sequences in character arrays.

Sample Output

AC AD AH AS 2C 2D 2H 2S 3C 3D 3H 3S 4C 4D 4H 4S 5C 5D 5H 5S 6C 6D 6H 6S 7C 7D 7H 7S 8C 8D 8H 8S 9C 9D 9H 9S 10C 10D 10H 10S JC JD JH JS QC QD QH QS KC KD KH KS J J


Try it online!

• Hint: you can use a single printf to get rid of all putchars. Jun 11 '18 at 21:57
• Jun 11 '18 at 22:00
• Regarding your method of output, the OP does not allow printing. Jun 11 '18 at 22:03
• Building on Jonathan Frech and Dennis 113 bytes Aug 5 '19 at 5:04

Oracle SQL, 164 bytes

Not a golfing language but...

SELECT CASE WHEN LEVEL>52THEN'J'ELSE DECODE(MOD(LEVEL,13),1,'A',11,'J',12,'Q',0,'K',MOD(LEVEL,13))||SUBSTR('HDSC',CEIL(LEVEL/13),1)END FROM DUAL CONNECT BY LEVEL<55


Try it online - SQL Fiddle

• I love that someone answered this with Oracle SQL Jun 13 '18 at 12:38
• postgres nearly beats this with just a string 172 bytes, 'select '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'' Jun 13 '18 at 13:43
• @dwana That is not an array of strings (or, since this is SQL, a set of rows). You would need to split the string into rows (or columns) to meet the question's specifications. If you want to do that as a separate PostgreSQL solution then I would like to see that.
– MT0
Jun 13 '18 at 13:47
• sorry, didn't see the array requirement Jun 13 '18 at 13:53

Lua, 156127138 129 bytes

loadstring'r={"J","J"}for x=1,52 do p=x%4+1r[#r+1]=({"A",2,3,4,5,6,7,8,9,10,"J","Q","K"})[x%13+1]..("SDHC"):sub(p,p)end return r'


Try it online!

Based on Jo King's code. As he suggested in the comments, my original answer wasn't valid (I'm still learning how code golf works 😬), and linked a better and valid answer. Then I made it smaller.

Original solution (156 bytes):

r={}s="SDHC"c={"J","Q","K"}t=table.insert for x in s:gmatch"."do for y=1,13 do t(r,(y==1 and"A"or y>10 and c[y-10]or y)..x)end end for _=1,2 do t(r, "J")end
r={} -- initializes the result table
s="SDHC" -- initializes the suits' string, it's better to be a string because we're just looping through it
c={"J","Q","K"} -- initializes some of the special cards

t=table.insert -- stores the table.insert call inside the 't' variable

for x in s:gmatch"."do -- loops through the suits, calling each one 'x'
for y=1,13 do -- 'y' is the current card

t(r,(y==1 and"A"or y>10 and c[y-10]or y)..x) -- adds the card accompanied by the suit to the result ('r') table
-- y==1 and"A"or y>10 and c[y-10]or y  means if we're at the first card, it's an "A", else if we're past the 10th card, it's a special card, else, it's the number itself

end
end
for _=1,2 do t(r, "J")end -- loop 2 times, adding a "J" to the result table


I just want to say that I'm new to this Code Golf stuff, so if I'm doing something wrong, feel free to tell me. I know this answer isn't one of the smallest, I just wanted to challenge myself.

If you have suggestions for reducing my code you can say too. :)

• Welcome to the site! Jul 21 '18 at 20:23
• @WW thanks! Hahah :D Jul 21 '18 at 21:34
• What happens with the table r? Either you need to print it to STDOUT, or change this to a function and return r
– Jo King
Jul 22 '18 at 9:03
• I'm no expert with Lua, but here's a valid 142 byte anonymous function
– Jo King
Jul 22 '18 at 9:37
• 138 bytes
– Jo King
Jul 22 '18 at 9:54

Perl 6,  43  42 bytes

{|(|(2..10),|<A J Q K>X~ <S D H C>),|<J J>}


Try it

{|(|(^9+2),|<A J Q K>X~ <S D H C>),|<J J>}


Try it from Jo King

Expanded:

{  # bare block lambda

|(  # flatten into outer list

|(  # flatten into left-side list for X~
^9 + 2
# 0+2 ..^ 9+2
#   2 ..^ 11
#   2 ..  10
),
|   # flatten into left-side list for X~

< A J Q K >

X~    # cross using &infix:« ~ » (string concatenation)

<S D H C>

),
|< J J > # flatten two Js into outer list
}

• 41 bytes
– Jo King
Jan 10 '19 at 20:09

QBasic 4.5, 114142 127 bytes

dim r$(54) FOR i=1TO 52 m=i MOD 13 r$(i)=MID$("JQKA2345678910",1+m,1-(m=12))+MID$("CDHS",(i-1)\13+1,1)
NEXT
r$(53)="J r$(54)="J


Release Notes:

• V1.0 Initial deploy
• V1.1 Misread the challenge requirements, so switched to a more expensive array r$. All the rest of the code is pretty much the same. • V1.2 Suggestions from @TaylorScott lead to a complete rewrite saving 15 bytes! Sample output If we add this snippet to our code, we can see what is put into r$:

for i = 1 to ubound(r$) ?r$(i)
next

QC
KC
AC
2C
3C
4C
5C
6C
7C
8C
9C
10C
JC
QD
KD
[... snip ...]
6S
7S
8S
9S
10S
JS
J
J


But how? Well, let me tell you:

dim r$(54) ' create a 54-slot array for our results FOR i=1TO 52 ' Loop through the numbers 1-52 in var i m=i MOD 13 ' Take i mod 13 to select a value (saved as m) ' , and (not saved) i intdiv 13 to get a suit r$(i)=              ' assigns to slot i in the result array
MID$("JQKA2345678910" ' a substring from the string with all the values ,1+m ' from position 1-13 (13 % 13 = 0, but QBasic strings are 1-based. ' Hence the + 1) ,1-(m=12)) ' taking 1 char by default, and 2 for the Ten ' Note that m=12 evaluates to 0 for 0-11, and to -1 for 12 + MID$("CDHS",(i-1)\13+1,1)  ' and take 1 char from the suits-string
NEXT
r$(53)="J ' Then append 2 jokers r$(54)="J           ' These strings are auto-closed by the QBasic compiler.

• This does not meet the Array of strings requirement, and printing to STDOUT is explicitly forbidden Jun 13 '18 at 15:58
• @TaylorScott Thanks for noticing. Fixed now, @ 30 bytes extra. Jun 13 '18 at 16:29
• I think that you should be able to get the bytecount down by dropping the a$ and b$ vars and using a line something like r$(i)=MID$("JQKA2345678910",1+m,1-(m=12))+MID\$("CDHS",(i-1)\13+1,1) Jun 13 '18 at 18:31
• @TaylorScott Thanks! That reshuffling in the values-string is particularly clever. Nice! Jun 13 '18 at 18:49
• This is longer than just PRINT "<output>" Jun 29 '18 at 21:03

Pyth, 26 25 bytes

+ B\JsM*+tSTc"JQKA"1"CDHS


Saved a byte thanks to hakr14.
Try it here

Explanation

+ B\JsM*+tSTc"JQKA"1"CDHS
tST                Get the range from 2 to 10...
+   c"JQKA"1        ... plus the list ['J', 'Q', 'K', 'A'].
*            "CDHS   Take the Cartesian product with the suits.
sM                     Stick the ranks and suits together.

• +\J+\J and +*2]\J are equivalent and both 6 bytes, but the latter is considered better form, as it allows for up to 10 copies to be added before any additional bytes are needed. Jun 13 '18 at 2:05
• +\J+\J can be replaced with + B\J to save a byte. Nov 8 '18 at 16:45