32
\$\begingroup\$

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.
\$\endgroup\$
  • 2
    \$\begingroup\$ @KevinCruijssen that’s correct. The initial question specifies the numbers 2 to 10, and an array of strings as an output. \$\endgroup\$ – AJFaraday Jun 11 '18 at 9:26
  • 15
    \$\begingroup\$ I was just wondering if you could get 23456789 by multiplying 2 smaller numbers... only to discover it's prime! \$\endgroup\$ – match Jun 11 '18 at 11:57
  • 4
    \$\begingroup\$ @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. \$\endgroup\$ – Kevin Cruijssen Jun 11 '18 at 13:19
  • 5
    \$\begingroup\$ 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. \$\endgroup\$ – Dennis Jun 12 '18 at 15:05
  • 7
    \$\begingroup\$ 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. \$\endgroup\$ – Dennis Jun 12 '18 at 23:50

60 Answers 60

2
\$\begingroup\$

Haskell, 57 bytes

"J":"J":[c++[s]|c<-"10":map pure"AJQK23456789",s<-"SDHC"]

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Retina, 49 42 bytes


AJQK2345678910
1?.
$0H,$0S,$0D,$0C,
$
J,J

Credit to @mazzy's comment on my Java answer.
-7 bytes thanks to @ovs.

Try it online.

Explanation:

Start with "AJQK2345678910":


AJQK2345678910

For each character (with "10" as single character):
Replace it with "cH,cS,cD,cC" where c is this character:

1?.
$0H,$0S,$0D,$0C,

And append "J,J"

$
J,J
\$\endgroup\$
  • \$\begingroup\$ You can shorten this by 4 bytes by removing capturing groups and replacing $1 with $&. \$\endgroup\$ – ovs Jun 11 '18 at 12:43
  • 1
    \$\begingroup\$ 42 bytes \$\endgroup\$ – ovs Jun 11 '18 at 12:46
  • \$\begingroup\$ @ovs Thanks. Was about to remove the parenthesis at (1?.) and use $0, but the appending of J,J is certainly shorter. Figured it would be possible, but I don't golf that often in Retina, so didn't knew how to append and hadn't had to time to search in the docs more thoroughly. PS: What's the difference between $& and $0 in this case, if there is any? \$\endgroup\$ – Kevin Cruijssen Jun 11 '18 at 12:58
  • 1
    \$\begingroup\$ It seems like there is no difference, but $& is used more often in the Retina docs, so I got used to it. \$\endgroup\$ – ovs Jun 11 '18 at 13:57
  • 1
    \$\begingroup\$ $& comes from Perl, where it is the string matched by the last successful pattern match. (In Perl 6, you would use $/ with the prefix stringification op ~ instead) \$\endgroup\$ – Brad Gilbert b2gills Jun 11 '18 at 17:41
2
\$\begingroup\$

VBA + RegExp, 135 bytes

A declared function that takes no input and outputs to the out var, o.

This subroutine depends upon the Microsoft VBScript Regular Expression 5.5 reference.

Sub a(o)
Set r=New RegExp
r.Global=1
r.Pattern="(\w+)"
o=Split(r.Replace("A 2 3 4 5 6 7 8 9 10 J Q K","$1S $1H $1D $1C")&" J J")
End Sub

Note: The terminal " on line 4 is not counted in the bytecount as it is not necessary and is only included for SO's syntax highlighting

\$\endgroup\$
2
\$\begingroup\$

8th, 156 152 149 bytes

Code

[] ( >s a:push ) 2 10 loop ["J","Q","K","A"] a:+ ( nip dup ["C","D","S","H"] ( nip s:+ >r dup ) a:each drop ) a:each ["J","J"] ( r> a:push ) 52 times

Array result is available on TOS

Output

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

Ungolfed code

\ make array ["2","3","4","5","6","7","8","9","10"]
[] ( >s a:push ) 2 10 loop                

\ make array ["2","3","4","5","6","7","8","9","10","A","J","Q","K"]              
["J","Q","K","A"] a:+   

\ make 13 cards for each suit and store each card on r-stack                                   
( nip dup ["C","D","S","H"] ( nip s:+ >r dup ) a:each drop ) a:each

\ make array result reading previous cards from r-stack 
["J","J"] ( r> a:push ) 52 times   

\ array result is available on TOS. Display it and get rid of intermediate stuff
. cr
reset
\$\endgroup\$
2
\$\begingroup\$

MATLAB R2018a, 82 57 bytes

Thanks to @David:

s=["A" 2:10 "J" "Q" "K"]+["D";"S";"H";"C"];[s(:);"J";"J"]

My old code:

X=["J","J"];for n=["A",2:10,"J","Q","K"]for s=["S","H","C","D"]X=[X,n+s];end;end;X

I figure it doesn't need an explanation but in case someone's interested:

X=["J","J"] // Set up first two Jokers
 for n=["A",2:10,"J","Q","K"] // Set up array for A, 2, 3... to K
  for s=["S","H","C","D"] // Set up suits
   X=[X,n+s]; // "Glue" value and suit together and add to array
  end
 end
X // Print out the result

Output:

X =

1×54 string array

Columns 1 through 11

"J"    "J"    "AS"    "AH"    "AC"    "AD"    "2S"    "2H"    "2C"    "2D"    "3S"

Columns 12 through 22

"3H"    "3C"    "3D"    "4S"    "4H"    "4C"    "4D"    "5S"    "5H"    "5C"    "5D"

Columns 23 through 33

"6S"    "6H"    "6C"    "6D"    "7S"    "7H"    "7C"    "7D"    "8S"    "8H"    "8C"

Columns 34 through 43

"8D"    "9S"    "9H"    "9C"    "9D"    "10S"    "10H"    "10C"    "10D"    "JS"

Columns 44 through 54

"JH"    "JC"    "JD"    "QS"    "QH"    "QC"    "QD"    "KS"    "KH"    "KC"    "KD"
\$\endgroup\$
  • 1
    \$\begingroup\$ +1, I didn't know about using " for strings! This can be shortened in newer version of Matlab (=>2016b) s=["A" 2:10 "J" "Q" "K"]+["D";"S";"H";"C"];[s(:);"J";"J"] \$\endgroup\$ – David Jun 13 '18 at 21:20
2
\$\begingroup\$

Bash (if Unicode is allowed), 45 bytes

echo -e \\U1F0{{A..D}{{1..9},{A..E}},{CF,DF}}

...produces:

🂡 🂢 🂣 🂤 🂥 🂦 🂧 🂨 🂩 🂪 🂫 🂬 🂭 🂮 🂱 🂲 🂳 🂴 🂵 🂶 🂷 🂸 🂹 🂺 🂻 🂼 🂽 🂾 🃁 🃂 🃃 🃄 🃅 🃆 🃇 🃈 🃉 🃊 🃋 🃌 🃍 🃎 🃑 🃒 🃓 🃔 🃕 🃖 🃗 🃘 🃙 🃚 🃛 🃜 🃝 🃞 🃏 🃟

Try it online!

This should work wherever Unicode is supported (ex: LANG=en_US.UTF8, not LANG=C). I'm not sure, however, if this meets the conditions of the rules. In particular:

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

The Unicode answer has one string per element, and the images indeed show a value followed by a suit. The example output, however, shows two separate chars per element, so there's room for doubt.

If the Unicode approach is disallowed, the code can be easily trimmed down to 34 bytes:

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

Try it online!

...but that is no shorter than the existing answer by glenn jackman (albeit sorted).

Regardless, Unicode is a technique worth mentioning. If you're dealing out a deck of cards, you might as well use the nice little images which are probably already on your computer, even in a text-mode terminal.

As for the question about the rules, I think the best answer is for someone to develop a question format which intrinsically includes an automated unit test. Maybe someday...

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to the site. Unlike other forums all answers must include a complete solution to the problem, and I think you are correct that this does not technically fit the specifications of the problem. If you would like to add a complete solution to your answer you can do that (and keep your partial solution as a bonus) but without a complete solution answers are subject to deletion. \$\endgroup\$ – Post Rock Garf Hunter Jul 9 '18 at 17:05
  • \$\begingroup\$ Anyways, the unicode solution you have it prints out the knight card. \$\endgroup\$ – Zacharý Jul 23 '18 at 22:57
2
\$\begingroup\$

Gol><>, 46 44 bytes

"CDSH"4F:j9FL2+noao|j"AKQJ"4F$ooao||S"J`nJ";

Try it online!

Edit: Saved 2 bytes thanks to Jo King

Explanation:

"CDSH"4F:j9FL2+noao|j"AKQJ"4F$ooao||S"J`nJ";

"CDSH"                                        //Init the 4 suites
      4F                                      //Loop to iterate over the 4 suites
        :j                                    //Pop a copy of the current suite into the next loop
           9FL2+noao|                         //Loop for the output of cards 2-10
                    j                         //Pass current suite into next loop & pop it from the stack
                     "AKQJ"                   //Init the 4 pictures
                           4F$ooao|           //Loop 4 times to output the picture cards
                                   |          //Jump back to the for loop to iterate over all suites
                                    S"J`nJ";  //Output the two J and terminate programm
\$\endgroup\$
2
\$\begingroup\$

C (gcc), 86 bytes

f(i){for(i=54;i--;)printf(i<52?"1%c%c "+(i>3):"J ","023456789JQKA"[i/4],"HSDC"[i%4]);}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

MASM 5 MACRO (x86 machine code), 109 100 bytes

D LABEL BYTE
IRPC r,234567890JQKA
IRPC s,DSHC
IF'&r'EQ'0'
DB'1'
ENDIF
DB'&r','&s '
ENDM
ENDM
DB'J J'

Since machine code has no formal definition for "an array of variable length strings", this returns the elements as characters in contiguous memory, delimited by a separator byte (20H) with the label D as a pointer to the location in memory.

Obviously, this would all be a lot simpler and smaller (76 bytes) if we could use 'T' for 10, which would make all cards exactly 2 bytes in size and simply be an indexable array of DW (double-words). That's your Kolmogorov rub I suppose!

Here's a short test program that shows one possible way this could be utilized:

MOV  DX, OFFSET D
MOV  AH, 9
INT  21H
MOV  AH, 4CH
INT  21H

Output

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

CJam, 45 bytes

"A"]8,2f+'0f+"10"a+"JQK"++"SDHC"m*::+["J"_]+p

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Jelly, 24 bytes

⁵ḊṾ€;“AJQK”p“HSDC”;⁾JJẎ€

Try it online!

\$\endgroup\$
1
\$\begingroup\$

JavaScript (Node.js), 126 bytes

[..."SDHC"].map(a=>Array.apply(0,Array(13)).map((b,i)=>(i==0?'A':i>9?'JQK'[i-10]:i+1)+a)).reduce((a,b)=>a.concat(b),['J','J'])

Try it online!

\$\endgroup\$
1
\$\begingroup\$

C# (.NET Core), 140 bytes

x=>{var a=new string[54];a[0]=a[1]="J";int i=2;foreach(var s in"SDCH")foreach(var n in"023456789AJQK")a[i++]=(n=='0'?"10":n+"")+s;return a;}

Try it online!

-10 bytes thanks to Kevin Cruijssen

-1 byte by taking unused input

-18 bytes thanks to Corak

\$\endgroup\$
  • \$\begingroup\$ You can remove the {} of the foreach, and .ToString() can be +"". \$\endgroup\$ – Kevin Cruijssen Jun 11 '18 at 12:10
  • 2
    \$\begingroup\$ 116 bytes by creating a port of my Java answer: o=>(new System.Text.RegularExpressions.Regex("(1?.)").Replace("AJQK2345678910","$1H,$1S,$1D,$1C,")+"J,J").Split(','). Credit to @mazzy's comment. \$\endgroup\$ – Kevin Cruijssen Jun 11 '18 at 12:17
  • \$\begingroup\$ @KevinCruijssen huh, I thought I needed the {} because of the nested foreach. Thanks! I'm not going to use your java port given it's such a drastically different approach, I'll let you post that yourself. Also just realised I can take unused input to shave a byte \$\endgroup\$ – Skidsdev Jun 11 '18 at 12:33
  • 2
    \$\begingroup\$ I wonder if something could be done with new[]{"J","J"}.Concat(from s in "SDCH" from n in "023456789AJQK" select (n=='0'?"10":n+"")+s);, but the using alone would probably make it unpractical. \$\endgroup\$ – Corak Jun 11 '18 at 14:31
  • 1
    \$\begingroup\$ @Corak Ah, you're right the .ToArray() should be added for this particular challenge, in which case it's 119 bytes. But the System.Collections.Generic isn't necessary in this case. As you can see in the TIO I linked, with just the using System.Linq; it works, so only that one should be counted towards to byte-count. \$\endgroup\$ – Kevin Cruijssen Jun 12 '18 at 11:49
1
\$\begingroup\$

Red, 88 bytes

foreach s{HSDC}[foreach c['A 2 3 4 5 6 7 8 9 10 'J 'Q 'K][prin c print s]]prin['J"^/"'J]

Try it online!

As a list:

Red, 100 bytes

d:[]foreach s{HSDC}[foreach c['A 2 3 4 5 6 7 8 9 10 'J 'Q 'K][append d rejoin[c s]]]append d["J""J"]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Stax, 21 bytes

Å|R╦¥Ä└╥¿‼≈┴2½#d☺Iwa▐

Run and debug it

Explanation:

9{^$m"AJQK"+"HSDC"|*'JQPm Full program, unpacked
                          Stack ([] is array, "" string '' char): empty
9{  m                     Map each element in range [1, 9]
  ^                         Increment
   $                        Stringify
                          Stack: ["2", "3", "4", "5", "6", "7", "8", "9", "10"]
     "AJQK"+              Add "AJQK"
                          Stack: ["2", "3", "4", "5", "6", "7", "8", "9", "10", 'A', 'J', 'Q', 'K']
            "HSDC"        Push suits
                          Stack: "HSDC" ["2", "3", "4", "5", "6", "7", "8", "9", "10", 'A', 'J', 'Q', 'K']
                  |*      Cartesian join
                          Stack: [["2", 'H'], ["2", 'S'], ..., "AH", "AS", ...]
                    'J    Push "J"
                          Stack: "J" [...]
                      Q   Peek and print with newline
                          Stack: "J" [...]
                       P  Pop and print with newline
                          Stack: [...]
                        m Map, implicitly print each with a newline
\$\endgroup\$
1
\$\begingroup\$

SimpleTemplate, 69 bytes

This is a template-like language I've been developing, all written in PHP. The instructions on how to use it are available in the Github page.

J J{@setx"SDHC","23456789JQKA"}{@eachx.1 asN}{@eachx.0}{@echo" ",N,_}

Ungolfed:

J J
{@set chars "SDHC", "23456789JQKA"}
{@each chars.1 as number}
    {@each chars.0 suite}
        {@echo " ", number, suite}
    {@/}
{@/}


Due to a series of bugs, this is not the most optimal solution. A shorter (non-working but should work) version below (51 bytes):

J J{@each"23456789JQKA"asN}{@each"SDHC"} {@echoN,_}

This, however, doesn't work.

\$\endgroup\$
1
\$\begingroup\$

vim, 80 bytes

aoA J Q K<C-V><ESC>:r !seq 2 10<C-V><CR>o<C-V><ESC>V10kJ:s/ /H /g<ESC>
yy3P34lrSjrDjrC:g/./:norm dd@"
oJ J<ESC>

<C-V> is 0x16. <CR> is 0x0d. <ESC> is 0x1B

Annotated

a                                    " insert vim code into the buffer that:
   oA J Q K<C-V><ESC>                "   generates face cards
   :r !seq 2 10<C-V><CR>o<C-V><ESC>  "   generates 2-10
   V10kJ                             "   joins into one line
   :s/ /H /g<ESC>                    "   adds suit (hearts)
yy3P                                 " make 3 copies of code
34lrSjrDjrC                          " change suit for each copy
:g/./:norm dd@"              " replace each line with the results from running it
o J J<ESC>                   " Jokers

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Google Sheets, 86 Bytes

A worksheet function that returns an array of "cards" to the the calling cell and the 53 cells to its right.

=Split(RegExReplace("A 2 3 4 5 6 7 8 9 10 J Q K","(\w+)","$1S $1H $1D $1C ")&" J J","  

Note: This function ends with a trailing space

\$\endgroup\$
1
\$\begingroup\$

Twig, 83 82 bytes

J J{%for I in(2..9)|merge('AKQJ'|split)%} {{I~'SDHC'|split|join(' '~I)}}{%endfor%}

This outputs the suits grouped by the "number".

You can test it on: https://twigfiddle.com/lz9cuf

Old version:

\$\endgroup\$
1
\$\begingroup\$

Julia, 63 bytes

[["1"^(k<'1')*"$k$z"for k="A234567890JQK"for z="HSDC"];"J";"J"]

Explanation

[
    [
        "1"^(k<'1')           # "1" if k is lexicographically before '1'
                              # which here only happens if k is '0'
        *"$k$z"               # concatenated to k and z
        for k="A234567890JQK" # for k in ranks
        for z="HSDC"          # and z in suits
    ]
    ;"J"                      # then concatenate 2 jokers
    ;"J"
]
\$\endgroup\$
1
\$\begingroup\$

Yabasic, 123 bytes

Dim r$(54)
r$(1)="J"
r$(2)="J"
For i=0To 51
r$(i+3)=Mid$("JQKA2345678910",1+i/4,1+(i/4>=12))+Mid$("CDHS",Mod(i,4)+1,1)
Next

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Groovy, 68 66 60 bytes

This is my first stab at a golf challenge, hope I get everything right.

68 byte version

[*2..10,*'AKQJ'.grep()].collectMany{n->'HSDC'.collect{n+it}}+['J']*2

Try it here


66 byte version

[*2..10,*'AKQJ'.grep()].inject([]){a,e->a+'HSDC'*.plus(e)}+['J']*2

Try it here


60 byte version

'HSDC'.grep().sum{[*2..10,*'AKQJ'.grep()]*.plus(it)}+['J']*2

Try it here

\$\endgroup\$
  • \$\begingroup\$ Welcome to Code Golf! Nice work! One thing, tho, it's usually preferable to add a link to an online interpreter so folks can verify your solution works. Here's one for your solution: groovyconsole.appspot.com/script/5194941521199104 (You might like to add that to your answer). \$\endgroup\$ – AJFaraday Jun 14 '18 at 15:29
1
\$\begingroup\$

Cjam, 29 26 bytes

B,2>"AJQK"+"SDHC"m*"JJ"+N*

Try it online!

Explanation:

B,2>        e# Generate the range [2, 10]
"AJQK"+     e# add the list with "AJQK"
            e# which generates all the 13 cards
"SDHC"      e# Push the variants
m*          e# Cartesian product
"JJ"+       e# Add 2 J's to the list
N*          e# And join the list items with newlines

Note:

  1. The previous count was incorrect; it should be 29 instead of 28.
  2. The challenge said the order doesn't matter, so 3 bytes off!
\$\endgroup\$
1
\$\begingroup\$

Pyth - 32 bytes

K+r2hTc"JQKA"1\J\JJ"SDHC"VJVK+HN

Explanation:

K+r2hTc"JQKA"1\J\JJ"SDHC"VJVK+HN
K                                 Assign variable K to
  r2hT                            Range from 2 to 10 plus 1
 +                                Plus
      c"JQKA"1                    Length 1 substrings of "JQKA"

              \J\J                Print 1 character string "J" twice

                  J"SDHC"         Assign J to "SDHC"

                         VJ       For N in J
                           VK     For H in K
                             +HN  Implicitly print H+N
\$\endgroup\$
1
\$\begingroup\$

PicoLisp, 181 171 bytes

(replaced ifn with if)

(setq c '(A 2 3 4 5 6 7 8 9 10 J Q K))
(de z (s l)(if (<> l NIL) (cons (pack (car l) s) (z s (cdr l)))))
(setq d (conc (z 'C c) (z 'D c) (z 'H c) (z 'S c) (list "J" "J")))

Sample output:

bash$ pil + 
: (load 'cards.l)
-> ("AC" "2C" "3C" "4C" "5C" "6C" "7C" "8C" "9C" "10C" "JC" "QC" "KC" "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" "AS" "2S" "3S" "4S" "5S" "6S" "7S" "8S" "9S" "10S" "JS" "QS" "KS" "J" "J")
: d              
-> ("AC" "2C" "3C" "4C" "5C" "6C" "7C" "8C" "9C" "10C" "JC" "QC" "KC" "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" "AS" "2S" "3S" "4S" "5S" "6S" "7S" "8S" "9S" "10S" "JS" "QS" "KS" "J" "J")
:  

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Brain-Flak, 276 bytes

((((((((()()())){}{})())[][])<>()())(<()>))<>[][][]){(<>)((((([()()()])){}{})[()])()){(({}<>(<(({})<>)>)()))}{}{}(((((()()()){}())(<<>(({})<>)>)((()()())){}{})(<<>(({})<>)>)())(<<>(({})<>)>)(()()()){})<>({}<>)<>}<>{{({}((((()()()){}()){}){}()){}<>)<>}{}<>((()()()()()){})<>}<>

Try it online!

Prints each card on its own line, with a leading newline.

Explanation:

((((((
((()()())){}{})  # Push 9 to represent  'C'
())              # Push 10 to represent 'D'
[][])            # Push 14 to represent 'H'
<>()())(<()>))   # Push 16, 0, 16 to the other stack to represent the Jokers
<>[][][])        # Push 25 to represent 'S'
{  # Loop over each suit
  (<>)  # Push 0 for a newline
  ((
    ((([()()()])){}{})  # Push -9 to represent '1'
    [()])               # Push -10 to represent '0'
  ())   # Push -9 to use as a counter
  {  # Loop 9 times to push the number cards
    (({}  # Store counter
     <>(<(({})<>)>)  #Push current suit and newline
    ()))  # Decrement counter and push twice, once as the number
  }{}{}
  ((((
    (()()()){}())  # Push 7 as 'A'
    (<<>(({})<>)>) # Push suit and newline
    ((()()())){}{})# Push 16 as 'J'
    (<<>(({})<>)>) # Push suit and newline
    ())            # Push 17 as 'K'
    (<<>(({})<>)>) # Push suit and newline
    (()()()){})    # Push 23 as 'Q'
  <>({}<>)<>       # Push suit
}
<>
{  # Loop over all output
  {  # Add 58 to each number
    ({}((((()()()){}()){}){}()){}<>)<>
  }
  {}<>((()()()()()){})<>  # And turn 0s into newlines
}<>  # Implicit output
\$\endgroup\$
1
\$\begingroup\$

Kotlin, 76 bytes

("A2345678910JQK".replace(Regex("1?."),"$0C $0D $0H $0S ")+"J J").split(" ")

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Tcl, 76 bytes

lmap n {S C H D} {lmap v {A K Q J 2 3 4 5 6 7 8 9 10} {puts $v$n}}
puts J\nJ

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Plain TeX, 348 bytes

It's just text printed as if it were an array, but that is close enough I think. It's not like TeX has native arrays anyway (although I do use some form of arrays in the code).

Short answer:

\newcount\i\let\c\csname\let\e\endcsname\let\t\the\def~#1,#2,#3{\expandafter\def\c#2\t#1\e{#3}}\i3 ~\i,a,K~\i,s,D\i4 ~\i,a,Q~\i,s,C\i5 ~\i,a,J~\i,s,S\i2 ~\i,a,A~\i,s,H\newcount\v[\loop\v2{\loop"\t\v\c s\t\i\e", \ifnum\v<10\advance\v1\repeat}{\loop"\c a\t\v\e\c s\t\i\e", \ifnum\v<5\advance\v1\repeat}\break\ifnum\i<5\advance\i1\repeat "J", "J"]\bye

Long answer, with comments as explanation:

%First shorten some commands
\let\c\csname
\let\e\endcsname
\let\t\the
%then define the function todefine and fill the arrays
\def ~#1,#2,#3{\expandafter\def\c #2\t#1\e{#3}}
%main counter in this program
\newcount\i
\i3
%array a contains A, K, Q, J, the 'picture cards'
%array s contains D, C, S, H, the suits
%indexing is 2 to 5 so the same counter as for the 2...10 can be used
 ~\i,a,K
 ~\i,s,D
\i4
 ~\i,a,Q
 ~\i,s,C
\i5
 ~\i,a,J
 ~\i,s,S
%2 is the last one as we want i to be 2 after this
\i2
 ~\i,a,A
 ~\i,s,H
%the other counter
\newcount\v
%outer loop loops over the suits
[\loop
    %2 is the starting point for the arrays and the numbers
    \v2
    %brackets to ensure local use of \v
    %first loop iterates over the numbers
    {
     \loop
     %this prints v and the current suit
     "\t\v \c s\t\i\e", 
     \ifnum\v<10
        %\advance \v by 1
        \advance\v1
     \repeat
    }
    %...second loop over the picture cards
    {
     \loop
     "\c a\t\v\e \c s\t\i\e", 
     \ifnum\v<5
        \advance\v1
     \repeat
    }
    %to prevent the output escaping the file on the right border
    \break
    \ifnum\i<5
        \advance\i1
 \repeat
 %then print the jokers
 "J", "J"
]
\bye
\$\endgroup\$
0
\$\begingroup\$

C (gcc), 129 bytes

char*v[]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};main(i){for(i=0;i<13;)printf("%sS %1$sD %1$sH %1$sC ",v[i++]);puts("J J");}

C (gcc), 89 bytes

main(i){for(i=0;i<13;)printf("%cS %1$cD %1$cH %1$cC ","A23456789XJQK"[i++]);puts("J J");}

2018-09-16: -12 @gastropner

\$\endgroup\$
  • 1
    \$\begingroup\$ You can forgo declaring v and index into the literal to shave some bytes off. \$\endgroup\$ – gastropner Aug 7 '18 at 10:32
  • \$\begingroup\$ Suggest i=13;i--; instead of i=0;i<13; and ,"KQJX98765432A"[i] instead of "A23456789XJQK"[i++] \$\endgroup\$ – ceilingcat Aug 10 '18 at 3:36
  • \$\begingroup\$ @ceilingcat what stops the loop? \$\endgroup\$ – SIGSTACKFAULT Aug 17 '18 at 15:49
  • \$\begingroup\$ @Blacksilver the loop stops when i--==0 \$\endgroup\$ – ceilingcat Aug 17 '18 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.