कार्ड का एक डेक उत्पन्न करें


32

यहां दो 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"
]

यह इस तरीके से बना है:

  • चार सूट हैं; दिल, हुकुम, हीरे, और क्लब (एच, एस, डी, सी)।
  • प्रत्येक सूट में 2 से 10 की संख्या के लिए एक कार्ड, प्लस 4 'चित्र' कार्ड, ऐस, जैक, क्वीन और किंग (ए, जे, क्यू, के) हैं।
  • सूट और मूल्य के प्रत्येक संयोजन के लिए, सरणी में एक आइटम होना चाहिए, जो एक स्ट्रिंग है, और सूट के बाद के मूल्य से बना है (इन के बीच व्हाट्सएप की अनुमति है)।
  • उसके ऊपर, दो जोकर कार्ड ('J') हैं।
  • कृपया किसी भी भाषा में लिखें।
  • इसे गोल्फ! इस आउटपुट को बाइट्स की सबसे छोटी संख्या में उत्पादित करने का प्रयास करें।
  • इससे कोई फर्क नहीं पड़ता कि आउटपुट किस क्रम में है।

2
@ केविनक्रूजसेन यह सही है। प्रारंभिक प्रश्न संख्या 2 से 10 और आउटपुट के रूप में स्ट्रिंग्स की एक सरणी को निर्दिष्ट करता है।
AJFaraday

15
मैं सोच रहा था कि क्या आप 2 छोटी संख्याओं को गुणा करके 23456789 प्राप्त कर सकते हैं ... केवल यह जानने के लिए कि यह प्रमुख है!
मैच

4
के बाद से उत्पादन का क्रम महत्वपूर्ण नहीं है, हो सकता है आप अभी भी इसे कम संख्या के साथ साथ यह समाप्त होने से बना सकते हैं @match 2या 4या कुछ और तो यह एक प्रमुख अब और नहीं है।
केविन क्रूज़सेन

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

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

जवाबों:




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

That more than 2.5 time shorter than my solution. Well done.
The random guy

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


9

brainfuck, 550 504 bytes

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

Try it online!

Old answer, also online!


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


3
try "AJQK2345678910".replace("1?.","$0H,$0S,$0D,$0C,")+"J,J" and split it.
mazzy

1
Smart @mazzy Thanks. And was already editing it, Olivier. :)
Kevin Cruijssen

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

1
@mazzy Oh, didn't even knew $0 was possible in Java. TIL, thanks. :)
Kevin Cruijssen

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.

┌─┬─┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬───┬───┬───┬───┐
JJAHACADASKHKCKDKSJHJCJDJSQHQCQDQS2H2C2D2S3H3C3D3S4H4C4D4S5H5C5D5S6H6C6D6S7H7C7D7S8H8C8D8S9H9C9D9S10H10C10D10S
└─┴─┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴───┴───┴───┴───┘

'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.
Kevin Cruijssen

@KevinCruijssen Thanks, I couldn't figure out how to do that, so I used multiple bullet points hah
Kritixi Lithos

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

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

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


1
This was my exact answer, although I think I used double quotes instead of single quotes.
Giuseppe

Sorry, have I double-posted your answer ? I checked but I couldn't find any R answer...
digEmAll

Oh no I had just typed it all up myself in TIO before seeing yours :-)
Giuseppe

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

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

6

Powershell, 63 61 59 56 bytes

-3 bytes: thanks ConnorLSW

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

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

1
cool! any idea how to remove ````?
mazzy

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


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

That's a pretty thorough answer...
AJFaraday


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

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


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.


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

@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

4

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 :-)
Marty Neal

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

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

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]


Wouldn't [H.$t,S.$t,D.$t,C.$t] be shorter than explode?
Jo King

You are absolutely right, gonna take your advise, thank you.
Francisco Hahn

1
73 bytes: Try it online!
Night2

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

1
@Nigth2 i had no idea you can use array_push($arr, $item1,$item2,$item3...$itemN) like that, nice one
Francisco Hahn

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


@EriktheOutgolfer How did you generate that?
mbomb007

1
I 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

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

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

3

J, 41 bytes

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

Try it online!


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

@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

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.


oh haha I didn't notice this, I commented this solution on the other one
Giuseppe

@Giuseppe I was very close to comment instead of posting myself. I guess I just couldn't resist the urge to answer :)
JayCe

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

@I was just experimenting with that :) so both digemall and I can golf one byte thanks to you :)
JayCe

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.


1
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.
Jonathan Frech

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

1
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?
Jonathan Frech

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

1
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.
Jonathan Frech

3

Javascript (ES6) 77 74 72 bytes

This is a complete program.

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

1
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).
Rick Hitchcock

Awesome suggestion! Thanks.
MattH

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!


Hint: you can use a single printf to get rid of all putchars.
Dennis


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

Building on Jonathan Frech and Dennis 113 bytes
ceilingcat

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


2
I love that someone answered this with Oracle SQL
AJFaraday

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

@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

sorry, didn't see the array requirement
dwana

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


1
Welcome to the site!
Wheat Wizard

@WW thanks! Hahah :D
Visckmart

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

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


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
}


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.

This does not meet the Array of strings requirement, and printing to STDOUT is explicitly forbidden
Taylor Scott

@TaylorScott Thanks for noticing. Fixed now, @ 30 bytes extra.
steenbergh

1
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)
Taylor Scott

1
@TaylorScott Thanks! That reshuffling in the values-string is particularly clever. Nice!
steenbergh

This is longer than just PRINT "<output>"
Tornado547

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.

+\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

@hakr14 True, but I'm not into code golf for the sake of writing the cleanest or most generalizable code.

+\J+\J can be replaced with + B\J to save a byte.
hakr14
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.