Generate a deck of cards

32

10

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.

AJFaraday

Posted 2018-06-11T08:52:25.837

Reputation: 10 466

Related – Shaggy – 2018-06-11T08:59:26.807

Are we allowed to print each card to STDOUT instead of returning a list/array? – Kevin Cruijssen – 2018-06-11T09:01:56.147

Can we use T instead of 10? – Kevin Cruijssen – 2018-06-11T09:08:12.553

@KevinCruijssen no – AJFaraday – 2018-06-11T09:14:00.933

1@AJFaraday No for both my questions? So String list/array and 10 are both mandatory? – Kevin Cruijssen – 2018-06-11T09:15:39.477

2@KevinCruijssen that’s correct. The initial question specifies the numbers 2 to 10, and an array of strings as an output. – AJFaraday – 2018-06-11T09:26:57.413

Can we output C9 instead of 9C? – user41805 – 2018-06-11T10:18:48.540

@Cowsquack "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" – AJFaraday – 2018-06-11T10:19:29.787

15I was just wondering if you could get 23456789 by multiplying 2 smaller numbers... only to discover it's prime! – match – 2018-06-11T11:57:28.053

Can we output the two Js as characters instead of strings? (Only true for some languages.) Additionally, can we output the other cards as lists of an integer and a character instead of strings? – Erik the Outgolfer – 2018-06-11T12:02:36.020

@EriktheOutgolfer I'm afraid it's pretty prescriptive, an array of strings. – AJFaraday – 2018-06-11T12:05:35.017

4@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. – Kevin Cruijssen – 2018-06-11T13:19:37.090

As a poker aficionado, I have to second @KevinCruijssen 's comment of using T - it's much, much more common. – corsiKa – 2018-06-11T20:39:46.590

2@corsiKa it’s also common to leave the jokers out in poker. Both the numeral 10 and the jokers add a little complexity to the challenge. To change that now would make it an uneven challenge. – AJFaraday – 2018-06-11T20:42:47.083

1@match The product of two positive integers is always smaller than their concatenation. – Dennis – 2018-06-11T21:46:48.137

@match You could do 91**3*35 if your language has a short built-in for cube. – Arnauld – 2018-06-11T23:51:22.987

1I dont see the point of disallowing output to stdout. For a lot of languages without structures like functions, arrays or even strings, that's the only way to actually output anything – Jo King – 2018-06-12T01:33:17.170

@JoKing Mostly because in languages which have an array structure, outputting to STDOUT might be shorter than collecting items into an array. – AJFaraday – 2018-06-12T08:17:52.363

I don't think there's anything wrong with having shorter code... – Jo King – 2018-06-12T09:31:55.153

1@JoKing Having shorter code is the goal of code golf. Changing the rules part-way to make the code shorter is utterly un-levelling the playing field. – AJFaraday – 2018-06-12T09:46:49.317

2The playing field isn't very level when you've excluded a majority of languages – Jo King – 2018-06-12T09:55:10.670

1@JoKing For the purposes of this particular challenge, I've made a decision not to modify the rules when there's 20+ responses already. Perhaps raise a meta question about it? – AJFaraday – 2018-06-12T09:56:27.310

5Rules 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. – Dennis – 2018-06-12T15:05:09.487

@Dennis the spec explicitly states an array of strings. – AJFaraday – 2018-06-12T23:34:09.327

7That 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. – Dennis – 2018-06-12T23:50:01.243

1What about "Rules of Bridge" in the returned array of strings? :) – billpg – 2018-06-13T15:50:29.763

1@billpg I kind of want to allow that. It wouldn't be fair to make everyone do it now, tho. – AJFaraday – 2018-06-13T15:56:12.567

1Can we use lowercase letters? – Shaggy – 2018-06-18T15:59:57.847

Answers

29

JavaScript (ES6), 62 60 bytes

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

Try it online!

Arnauld

Posted 2018-06-11T08:52:25.837

Reputation: 111 334

Smooth moves!!! – Code Whisperer – 2018-06-11T14:46:47.637

I didn't know spread syntax existed until I read this -- very cool – logic8 – 2018-06-15T17:29:20.983

24

Bash 43 34 bytes

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

Try it online!

glenn jackman

Posted 2018-06-11T08:52:25.837

Reputation: 343

19 bytes shorter – Digital Trauma – 2018-06-11T17:34:52.657

I did not think braces were nestable. Thanks. – glenn jackman – 2018-06-11T17:53:39.663

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! – aschepler – 2018-06-13T01:21:57.317

1Technically brace expansion is not a glob pattern, it is its own special syntax – glenn jackman – 2018-06-14T03:19:30.887

13

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

Jo King

Posted 2018-06-11T08:52:25.837

Reputation: 38 234

That more than 2.5 time shorter than my solution. Well done. – The random guy – 2018-06-12T14:52:30.223

11

05AB1E, 28 27 25 24 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".

Kevin Cruijssen

Posted 2018-06-11T08:52:25.837

Reputation: 67 575

9

brainfuck, 550 504 bytes

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

Try it online!

Old answer, also online!

The random guy

Posted 2018-06-11T08:52:25.837

Reputation: 1 262

8

Java 10, 153 151 125 77 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

Kevin Cruijssen

Posted 2018-06-11T08:52:25.837

Reputation: 67 575

r[i++]=r[i]="J"; No need for the final ++. – Olivier Grégoire – 2018-06-11T09:56:41.127

3try "AJQK2345678910".replace("1?.","$0H,$0S,$0D,$0C,")+"J,J" and split it. – mazzy – 2018-06-11T11:51:07.520

1Smart @mazzy Thanks. And was already editing it, Olivier. :) – Kevin Cruijssen – 2018-06-11T12:02:16.340

2

cool! I believe it is possible to remove 2 bytes more - brackets in the pattern. see https://regex101.com/r/aDbz9C/1/

– mazzy – 2018-06-11T12:35:23.260

1@mazzy Oh, didn't even knew $0 was possible in Java. TIL, thanks. :) – Kevin Cruijssen – 2018-06-11T12:54:12.707

7

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)

user41805

Posted 2018-06-11T08:52:25.837

Reputation: 16 320

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. – Kevin Cruijssen – 2018-06-11T11:31:05.577

@KevinCruijssen Thanks, I couldn't figure out how to do that, so I used multiple bullet points hah – user41805 – 2018-06-11T11:39:25.713

Yeah, I thought so, that's why I changed it. :) You need multiples of four leading spaces before the - to indent it. – Kevin Cruijssen – 2018-06-11T11:51:01.137

7

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

enter image description here

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

ovs

Posted 2018-06-11T08:52:25.837

Reputation: 21 408

7

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

digEmAll

Posted 2018-06-11T08:52:25.837

Reputation: 4 599

1This was my exact answer, although I think I used double quotes instead of single quotes. – Giuseppe – 2018-06-11T12:44:37.573

Sorry, have I double-posted your answer ? I checked but I couldn't find any R answer... – digEmAll – 2018-06-11T13:14:11.377

Oh no I had just typed it all up myself in TIO before seeing yours :-) – Giuseppe – 2018-06-11T13:26:52.453

1Yes 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. – JayCe – 2018-06-11T15:00:03.663

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!

– Giuseppe – 2018-06-11T18:03:40.237

Modified: thanks to both @JayCe and @ Giuseppe ;) – digEmAll – 2018-06-11T18:35:40.540

6

Powershell, 63 61 59 56 bytes

-3 bytes: thanks ConnorLSW

2..10+'AJQK'[0..3]|%{"$_`H";"$_`S";"$_`D";"$_`C"};,'J'*2

mazzy

Posted 2018-06-11T08:52:25.837

Reputation: 4 832

1-3 using string to array for the first part : 2..10+'AJQK'[0..4]|%{"$_`H";"$_`S";"$_`D";"$_`C"};,'J'*2 – colsw – 2018-06-11T14:43:25.860

1cool! any idea how to remove ````? – mazzy – 2018-06-11T14:57:49.320

1as 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. – colsw – 2018-06-11T14:59:30.730

6

Perl 5, 41 bytes

sub{J,J,map<"$_"{S,D,H,C}>,A,2..10,J,Q,K}

Try it online!

Dom Hastings

Posted 2018-06-11T08:52:25.837

Reputation: 16 415

1This has taught me something really interesting about globbing. Nice. – AmbroseChapel – 2018-06-12T23:33:57.500

5

Python 3, 67 64 bytes

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

Try it online!


Python 2, 78 76 74 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

TFeld

Posted 2018-06-11T08:52:25.837

Reputation: 19 246

That's a pretty thorough answer... – AJFaraday – 2018-06-11T09:15:15.363

64 bytes – ovs – 2018-06-11T11:07:21.863

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? – Enrico Borba – 2018-07-04T02:38:53.333

5

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

ngn

Posted 2018-06-11T08:52:25.837

Reputation: 11 449

5

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.

BradC

Posted 2018-06-11T08:52:25.837

Reputation: 6 099

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. – AJFaraday – 2018-06-12T07:15:01.730

@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 :) – BradC – 2018-06-12T13:29:57.053

4

Japt, 32 30 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

Shaggy

Posted 2018-06-11T08:52:25.837

Reputation: 24 623

4

PHP, 108 99 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]

Francisco Hahn

Posted 2018-06-11T08:52:25.837

Reputation: 591

Wouldn't [H.$t,S.$t,D.$t,C.$t] be shorter than explode? – Jo King – 2018-06-12T11:00:46.767

You are absolutely right, gonna take your advise, thank you. – Francisco Hahn – 2018-06-12T13:49:06.533

1

73 bytes: Try it online!

– Night2 – 2018-07-22T09:56:59.187

@Night2, nice aproach, tried something similar when i was writing this answer, but the OP asks for a String array as output. – Francisco Hahn – 2018-07-23T14:17:22.650

2

@FranciscoHahn, sorry, I didn't notice that! Here is a 87 bytes version then: Try it online!

– Night2 – 2018-07-23T17:09:32.607

1@Nigth2 i had no idea you can use array_push($arr, $item1,$item2,$item3...$itemN) like that, nice one – Francisco Hahn – 2018-07-23T17:13:35.257

4

Ruby, 61 bytes

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

Try it online!

G B

Posted 2018-06-11T08:52:25.837

Reputation: 11 099

That's some skill to use the J for both Jack and Joker :-) – Marty Neal – 2018-06-14T15:37:34.023

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 – Piccolo – 2018-08-10T01:27:58.560

4

C# .NET, 114 bytes

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

Port of my Java answer (credit to @mazzy).

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"
   .Concat(              //  And add:
     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'
                 "10"    //      Use 10 instead
                :        //     Else:
                 n+"")   //      Simply use the card item as is
                      +s)//     And append the suit
   .ToArray()            //  Convert the IEnumerable to an array

Kevin Cruijssen

Posted 2018-06-11T08:52:25.837

Reputation: 67 575

4

SMBF, 169 bytes

represents a literal NUL byte \x00.

<[.<]␀J J HA HK HQ HJ H01 H9 H8 H7 H6 H5 H4 H3 H2 SA SK SQ SJ S01 S9 S8 S7 S6 S5 S4 S3 S2 DA DK DQ DJ D01 D9 D8 D7 D6 D5 D4 D3 D2 CA CK CQ CJ C01 C9 C8 C7 C6 C5 C4 C3 C2

This is the naive solution.

Because this program contains a NUL byte, there's no easy way to use TIO. Run this in the Python interpreter using

data = bytearray(b'<[.<]\x00J J HA HK HQ HJ H01 H9 H8 H7 H6 H5 H4 H3 H2 SA SK SQ SJ S01 S9 S8 S7 S6 S5 S4 S3 S2 DA DK DQ DJ D01 D9 D8 D7 D6 D5 D4 D3 D2 CA CK CQ CJ C01 C9 C8 C7 C6 C5 C4 C3 C2')

mbomb007

Posted 2018-06-11T08:52:25.837

Reputation: 21 944

TIO – Erik the Outgolfer – 2018-08-07T15:24:13.773

@EriktheOutgolfer How did you generate that? – mbomb007 – 2018-08-07T15:43:40.977

1I opened the F12 developer tools, selected the text box by hovering, went to the console and, after I copied and pasted the part before the null byte, typed $0.value+='\0'. – Erik the Outgolfer – 2018-08-07T16:07:33.400

3

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

Neil

Posted 2018-06-11T08:52:25.837

Reputation: 95 035

3

J, 41 bytes

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

Try it online!

Galen Ivanov

Posted 2018-06-11T08:52:25.837

Reputation: 13 815

1'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. – Jonah – 2018-06-12T05:26:00.327

@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 :) – Galen Ivanov – 2018-06-12T06:27:16.527

3

C (gcc), 126 137 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.

LambdaBeta

Posted 2018-06-11T08:52:25.837

Reputation: 2 499

1I 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. – Jonathan Frech – 2018-06-11T15:19:57.163

1Except 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. – LambdaBeta – 2018-06-11T15:21:41.243

1If 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? – Jonathan Frech – 2018-06-11T15:34:33.493

1no, 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. – LambdaBeta – 2018-06-11T15:36:15.380

1I 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. – Jonathan Frech – 2018-06-11T15:41:30.090

The issue there is that z is in a variable and is the value of that variable. Many languages use 'inline blocks' as a valid submission format (e.g. J's unnamed verbs) this is similar in that it can be inlined directly. Note that I would consider the equal length second line of char*c[]={...}; invalid as it does not do what a C function normally would (return a new value on the stack). If you need a function then a second line of char*[54]f(){return {...};} would work I think. – LambdaBeta – 2018-06-11T15:45:37.353

Nope, you need a declaration in order to use an initializer. And this is the main reason this approach isn't valid. Not only is the expansion of c not (used in) a function, but it doesn't produce a value. It's just syntax tied to a declaration. – Jakob – 2018-06-11T15:52:39.863

No, you don't need a declaration. In a for loop you could have c[53] as identical to "J" without any variable being declared. That is exactly why I argue it is different. (the only issue being typing, but we abuse that all the time with our int functions taking pointers) Changing the line in the link to printf("%s ", (char*[54])c[i]) works fine. You could argue the need for +11 bytes to add the (char*[54]) in front of the array in c though. – LambdaBeta – 2018-06-11T15:55:51.910

Here is my reasoning why the macros are more functional than a variable declaration: Try it online!

– LambdaBeta – 2018-06-11T16:12:59.597

I get your deep copy argument that macros are more function-esk than variables, though I do not think that is enough for them to be on par with functions regarding the I/O consensus. – Jonathan Frech – 2018-06-11T16:34:31.720

Oops. You're right about initializers being expressions. I agree with Jonathan though that consensus is that a C submission must be a function or full program. – Jakob – 2018-06-11T16:37:52.673

I agree that macro functions are definitely borderline (which c is, despite having no argument list). The relevant meta post states that "The default should be "programs or functions" This includes function-like constructs, including J's verbs and GolfScript's and CJam's blocks. I would argue that C macros are as function-like as J's verbs or GolfScript's blocks (though not CJam's blocks, as they can be assigned to variables and manipulated, the analogue of function pointers) – LambdaBeta – 2018-06-11T16:50:32.057

You can remove the space after S(X).Also, add a comma after its definition, then use remove each comma after its call. – Zacharý – 2018-06-11T17:59:43.730

Suggest char*[] instead of char*[54] – ceilingcat – 2018-06-12T04:39:34.670

3

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.
+ B\J                       Add the jokers.

user48543

Posted 2018-06-11T08:52:25.837

Reputation:

+\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. – hakr14 – 2018-06-13T02:05:39.157

@hakr14 True, but I'm not into code golf for the sake of writing the cleanest or most generalizable code. – None – 2018-06-13T02:23:03.320

+\J+\J can be replaced with + B\J to save a byte. – hakr14 – 2018-11-08T16:45:01.060

3

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.

JayCe

Posted 2018-06-11T08:52:25.837

Reputation: 2 655

oh haha I didn't notice this, I commented this solution on the other one – Giuseppe – 2018-06-11T16:48:28.477

@Giuseppe I was very close to comment instead of posting myself. I guess I just couldn't resist the urge to answer :) – JayCe – 2018-06-11T17:35:31.143

iiiit's just as golfy as digemall's answer :-) try it online

– Giuseppe – 2018-06-11T17:44:27.890

@I was just experimenting with that :) so both digemall and I can golf one byte thanks to you :) – JayCe – 2018-06-11T17:47:39.307

3

Javascript (ES6) 77 74 72 bytes

This is a complete program.

`J,J,${[..."A23456789JQK",10].map(c=>[..."SDHC"].map(s=>c+s))}`.split`,`

MattH

Posted 2018-06-11T08:52:25.837

Reputation: 171

1Nice. 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). – Rick Hitchcock – 2018-06-11T17:19:07.803

Awesome suggestion! Thanks. – MattH – 2018-06-11T17:20:44.677

3

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 `J`s into outer list
}

Brad Gilbert b2gills

Posted 2018-06-11T08:52:25.837

Reputation: 12 713

41 bytes – Jo King – 2019-01-10T20:09:01.050

3

QBasic 4.5, 114 142 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
AD
[... 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.

steenbergh

Posted 2018-06-11T08:52:25.837

Reputation: 7 772

This does not meet the Array of strings requirement, and printing to STDOUT is explicitly forbidden – Taylor Scott – 2018-06-13T15:58:40.803

@TaylorScott Thanks for noticing. Fixed now, @ 30 bytes extra. – steenbergh – 2018-06-13T16:29:19.603

1I 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) – Taylor Scott – 2018-06-13T18:31:04.740

1@TaylorScott Thanks! That reshuffling in the values-string is particularly clever. Nice! – steenbergh – 2018-06-13T18:49:04.347

This is longer than just PRINT "<output>" – Tornado547 – 2018-06-29T21:03:12.850

3

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!

Bruce Lueckenhoff

Posted 2018-06-11T08:52:25.837

Reputation: 41

Hint: you can use a single printf to get rid of all putchars. – Dennis – 2018-06-11T21:57:56.057

1127 bytes. – Jonathan Frech – 2018-06-11T22:00:05.403

1

Regarding your method of output, the OP does not allow printing.

– Jonathan Frech – 2018-06-11T22:03:45.743

Building on Jonathan Frech and Dennis 113 bytes

– ceilingcat – 2019-08-05T05:04:12.993

3

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

MT0

Posted 2018-06-11T08:52:25.837

Reputation: 3 373

2I love that someone answered this with Oracle SQL – AJFaraday – 2018-06-13T12:38:22.017

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'' – dwana – 2018-06-13T13:43:17.477

@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 – 2018-06-13T13:47:50.127

sorry, didn't see the array requirement – dwana – 2018-06-13T13:53:32.530

3

Lua, 156 127 138 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. :)

Visckmart

Posted 2018-06-11T08:52:25.837

Reputation: 151

1Welcome to the site! – Post Rock Garf Hunter – 2018-07-21T20:23:02.370

@WW thanks! Hahah :D – Visckmart – 2018-07-21T21:34:15.763

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 – 2018-07-22T09:03:40.483

I'm no expert with Lua, but here's a valid 142 byte anonymous function

– Jo King – 2018-07-22T09:37:26.500

138 bytes – Jo King – 2018-07-22T09:54:05.023

2

Haskell, 57 bytes

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

Try it online!

Angs

Posted 2018-06-11T08:52:25.837

Reputation: 4 825

2

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

Kevin Cruijssen

Posted 2018-06-11T08:52:25.837

Reputation: 67 575

You can shorten this by 4 bytes by removing capturing groups and replacing $1 with $&. – ovs – 2018-06-11T12:43:34.317

142 bytes – ovs – 2018-06-11T12:46:31.393

@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? – Kevin Cruijssen – 2018-06-11T12:58:27.720

1

It seems like there is no difference, but $& is used more often in the Retina docs, so I got used to it.

– ovs – 2018-06-11T13:57:33.063

1$& 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) – Brad Gilbert b2gills – 2018-06-11T17:41:26.583

2

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"

Asinine

Posted 2018-06-11T08:52:25.837

Reputation: 21

1+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"] – David – 2018-06-13T21:20:48.990

2

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

Taylor Scott

Posted 2018-06-11T08:52:25.837

Reputation: 6 709

2

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

Chaos Manor

Posted 2018-06-11T08:52:25.837

Reputation: 521

2

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

William Dye

Posted 2018-06-11T08:52:25.837

Reputation: 21

2Welcome 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. – Post Rock Garf Hunter – 2018-07-09T17:05:06.733

Anyways, the unicode solution you have it prints out the knight card. – Zacharý – 2018-07-23T22:57:45.297

2

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

Gegell

Posted 2018-06-11T08:52:25.837

Reputation: 81

2

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!

gastropner

Posted 2018-06-11T08:52:25.837

Reputation: 3 264

2

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

640KB

Posted 2018-06-11T08:52:25.837

Reputation: 7 149

1

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

Skidsdev

Posted 2018-06-11T08:52:25.837

Reputation: 9 656

You can remove the {} of the foreach, and .ToString() can be +"". – Kevin Cruijssen – 2018-06-11T12:10:42.003

2

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.

– Kevin Cruijssen – 2018-06-11T12:17:50.553

@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 – Skidsdev – 2018-06-11T12:33:36.540

You should be able to remove both .ToCharArray() calls. A string is already an IEnumerable<char> – Corak – 2018-06-11T14:07:10.193

@Corak oh wow you're right! – Skidsdev – 2018-06-11T14:12:44.053

2I 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. – Corak – 2018-06-11T14:31:36.867

@Corak Oh nice. It's actually even shorter than the Regex-Replace I suggested above. 109 bytes to be exact, including the using System.Linq;.

– Kevin Cruijssen – 2018-06-12T10:36:22.927

@KevinCruijssen - I'm not familiar on how much "surrounding" code (header/footer) is allowed in code golf. So technically System.Collections.Generic needs to be counted, too, right? And technically the question asks for string[], so there would be an additional .ToArray() in there. – Corak – 2018-06-12T11:47:01.880

1

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

– Kevin Cruijssen – 2018-06-12T11:49:45.120

I've posted it as a separated answer. If you wanted to post it yourself @Corak let me know, then I'll remove that part of my answer and will make sure to upvote you when you've posted it. :) – Kevin Cruijssen – 2018-06-14T08:29:09.117

1

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!

Galen Ivanov

Posted 2018-06-11T08:52:25.837

Reputation: 13 815

1

CJam, 45 bytes

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

Try it online!

maxb

Posted 2018-06-11T08:52:25.837

Reputation: 5 754

1

Jelly, 24 bytes

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

Try it online!

Erik the Outgolfer

Posted 2018-06-11T08:52:25.837

Reputation: 38 134

1

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!

Luis felipe De jesus Munoz

Posted 2018-06-11T08:52:25.837

Reputation: 9 639

1

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

wastl

Posted 2018-06-11T08:52:25.837

Reputation: 3 089

Although a nice solution, I'm afraid it's currently invalid. You're currently printing the cards newline-delimited to STDOUT, but it should be output as a single list. It's currently hidden in the comments (see this comment - and the ones it's replying to, and this comment - including the one above it), so I can understand that you've missed it..

– Kevin Cruijssen – 2019-01-09T12:24:49.473

1

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:

Ismael Miguel

Posted 2018-06-11T08:52:25.837

Reputation: 6 797

1

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.

Ismael Miguel

Posted 2018-06-11T08:52:25.837

Reputation: 6 797

1

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!

Ray

Posted 2018-06-11T08:52:25.837

Reputation: 1 488

1

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

Taylor Scott

Posted 2018-06-11T08:52:25.837

Reputation: 6 709

1

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!

Taylor Scott

Posted 2018-06-11T08:52:25.837

Reputation: 6 709

1

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!

Chromium

Posted 2018-06-11T08:52:25.837

Reputation: 201

1

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

eaglgenes101

Posted 2018-06-11T08:52:25.837

Reputation: 577

1

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

Marty Neal

Posted 2018-06-11T08:52:25.837

Reputation: 111

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: https://groovyconsole.appspot.com/script/5194941521199104 (You might like to add that to your answer).

– AJFaraday – 2018-06-14T15:29:22.350

1

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!

Bruce Lueckenhoff

Posted 2018-06-11T08:52:25.837

Reputation: 41

1

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

Tornado547

Posted 2018-06-11T08:52:25.837

Reputation: 389

1

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

Jo King

Posted 2018-06-11T08:52:25.837

Reputation: 38 234

1

Kotlin, 76 bytes

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

Try it online!

JohnWells

Posted 2018-06-11T08:52:25.837

Reputation: 611

1

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!

sergiol

Posted 2018-06-11T08:52:25.837

Reputation: 3 055

0

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

Simon Klaver

Posted 2018-06-11T08:52:25.837

Reputation: 161

0

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

SIGSTACKFAULT

Posted 2018-06-11T08:52:25.837

Reputation: 585

1

You can forgo declaring v and index into the literal to shave some bytes off.

– gastropner – 2018-08-07T10:32:56.690

Suggest i=13;i--; instead of i=0;i<13; and ,"KQJX98765432A"[i] instead of "A23456789XJQK"[i++] – ceilingcat – 2018-08-10T03:36:34.957

@ceilingcat what stops the loop? – SIGSTACKFAULT – 2018-08-17T15:49:55.867

@Blacksilver the loop stops when i--==0 – ceilingcat – 2018-08-17T16:20:26.423