# Shuffle Up and Deal!

It is Friday and I am tired, so let's do a quick one! Take no input, however you should output all thirteen different numbered cards in a standard deck of cards. You should output 2 through Ace (Suit agnostic).

Each card has a top that is denoted with a space   and ten _ and another space .

The second row from the top is denoted with a / and ten spaces   and a \

The third row is the same as all the middle-ish rows excepts the character(s) denoting the card value appear two spaces to right (if at the top) or two space to the left (if at the bottom) of the edge.

Each middle-ish row is a simple | and ten spaces   and one more |

Finally the last line is a \ and ten _ and finally a /

If the value is multi-digit the overall width by height of the card should not change. (i.e. the 10 will not make the card's sides wider)

King Example:

 __________
/          \
| K        |
|          |
|          |
|          |
|          |
|          |
|        K |
\__________/


9 Example

 __________
/          \
| 9        |
|          |
|          |
|          |
|          |
|          |
|        9 |
\__________/


10 Example

 __________
/          \
| 10       |
|          |
|          |
|          |
|          |
|          |
|       10 |
\__________/


Output them in order from least to greatest (Aces are high!).

This is code-golf so the shortest code wins.

Have fun and have a fun weekend!

• May we have a 10 Example to see if the lower 10 is sticking the right edge or not? – Sunny Pun Oct 21 '16 at 19:17
• @SunnyPun why of course – jacksonecac Oct 21 '16 at 19:18
• Should the cards be arranged vertically, horizontally, or does it matter? – DLosc Oct 21 '16 at 19:24
• Left to right or top to bottom players choice. – jacksonecac Oct 21 '16 at 19:25

## PowerShell v2+, 120116114 108 bytes

2..10+[char[]]'JQKA'|%{$z=' '*(8-!($_-10));$x='_'*10;$y=' '*10;" $x /$y\
| $_$z|";,"|$y|"*5;"|$z$_ | $x/"}  Constructs a range 2..10 and does array concatenation with char-array JQKA. Feeds that into a loop |%{...}. Each iteration, we set z equal to an appropriate number of spaces (based on whether we're at card 10 or not), set x to 10 underscores, and set y to 10 spaces. Then, we begin our placements. We're going to leverage the default Write-Output to insert a newline between pipeline elements, so we just need to get the stuff on the pipeline. Note that in most places, we're using a literal newline rather than closing and reopening our strings to save a couple bytes. The first is just x with two spaces, then y with two slashes, then the | _z|" the pipe, a space, the appropriate number of spaces, and another pipe. This forms the top of the cards up to and including the value line. We have to semicolon here, since the next uses an array. The ,"|y|"*5 constructs a string-array, with the comma-operator, of the pipe with spaces - on output, each element of this array gets a newline for free. Then, the "|z_ | for the bottom value marking, and finally x with slashes for the bottom of the card. ### Output Snippet PS C:\Tools\Scripts\golfing> 2..10+[char[]]'JQKA'|%{z=' '*(8,7)[_-eq10];" ((x='_'*10)) ";"/((y=' '*10))\";"| _z|";,"|y|"*5;"|z_ |";"$x/"} __________ / \ | 2 | | | | | | | | | | | | 2 | \__________/ __________ / \ | 3 | | | | | | | | | | | | 3 | \__________/ __________ / \ | 4 | ...  • It's a strange day when PowerShell is winning! Nice work :) – Kade Oct 21 '16 at 20:15 • @Shebang Thanks! Sub-100 is so dang close, but not sure if I can make it. – AdmBorkBork Oct 21 '16 at 20:27 • [shakes fist] you're beating me by 3 bytes. THREE BYTES!! – Gabriel Benamy Oct 22 '16 at 0:01 # Python, 161160156 149 bytes One byte saved by Shebang This could use some work but here it is: o=" ";v="_"*10 for x in map(str,range(2,11)+list("JKQA")):print o+v+"\n/",o*9+"\\\n|",x.ljust(8),"|"+("\n|"+o*10+"|")*5+"\n|",o*6+x.ljust(3)+"|\n\\"+v+"/"  ## Explanation We make a list of all the ranks in order using map(str,range(2,11). Then we loop through each of the ranks and make a card. print o+"_"*10+"\n/",o*9+"\\\n|",x.ljust(8),"|"+("\n|"+o*10+"|")*5+"\n|",o*6+x.ljust(3)+"|\n\\"+"_"*10+"/"  We make the top of the card: o+v+"\n"  Then the rank goes on the left: "/",o*9+"\\\n|",x.ljust(8),"|"  We use .ljust because 10 is two long and all the other ones are one wide. Then we print the 5 rows in the middle: "|"+("\n|"+o*10+"|")*5+"\n|"  and the bottom rank: "\n|",o*6+x.ljust(3)+"|\n"  Finally we print the bottom of the card: "\\"+v+"/"  • Holy Moly that was quick – jacksonecac Oct 21 '16 at 19:23 • Your byte count seems off (I count 155). However, if you make a variable v="_"*10 and replace those instances will save you another byte! – Kade Oct 21 '16 at 22:32 ## JavaScript (ES6), 151 bytes f= _=>2345678910JQKA.replace(/.0?/g,s=> __________ / \\ | +(s+= +s).slice(0,4)+ | | .repeat(6)+s.slice(-4)+ | \\__________/ ) ; document.write('<pre>'+f()); • @Emigna Thanks, I forgot it in my other answer too. – Neil Oct 21 '16 at 20:10 # Perl, 128117 111 bytes map{printf$"."_"x10 ."
/".$"x10 .'\ | %-9s| '.("|".$"x10 ."|
")x5 ."|%9s |
\\"."_"x10 ."/
",$_,$_}2..10,J,Q,K,A


The 6 literal newlines save 1 byte each. This cannot be run directly from the command line because of the single quotes in lines 2 and 4 in order to save 1 byte by not having to escape a backslash.

Edit: I put Ace at the beginning, but it's supposed to be at the end. It doesn't change the byte count.

Edit 2: -11 bytes: Got rid of some unnecessary statements and added another literal newline. Everything is now output via a single printf.

Edit 3: -5 bytes thanks to @Ton Hospel. But for some reason, I'm getting 111 bytes instead of 112 at home when compared to at work, so I'm going with the byte count my home computer is giving me.

• You don't have to quote literals that are a valid symbol names, so _ x10 instead of "_"x10. Also qw is almost never useful. in golf. Use unquoted J,Q,K,A instead (even leaving out the ()) – Ton Hospel Oct 21 '16 at 21:43
• I get an interpreter error when I remove the quotes around the underscore: Can't locate object method "_" via package "x10" (perhaps you forgot to load "x10"?) at shuffle.pl line 1. Not sure why, but I won't fight the interpreter :( – Gabriel Benamy Oct 21 '16 at 22:21
• A bit more golfed (replace \n by real newline): printf' %2$s\n/%3$10s\\n| %-9s|\n'.'|%3$10s|\n'x5 .'|%1$9s |\n\%s/\n',$_,"_"x10for 2..10,J,Q,K,A – Ton Hospel Oct 22 '16 at 9:33 # PHP, 233 Bytes foreach([2,3,4,5,6,7,8,9,10,J,Q,K,A]as$k){for($c="",$i=0;$i<10;$i++)$c.=str_pad($i?$i>1&$i<9?"|":($i<2?"/":"\\"):" ",11,$i%9?" ":_).($i?$i>1&$i<9?"|":($i<2?"\\":"/"):" ")."\n";$c[113]=$c[28]=$k;$k>9&&$c[29]=$c[113]=0&$c[112]=1;echo$c;}

• Your last if can be replaced with $k>9&&$c[29]=$c[113]=0&$c[112]=1;, to save a few bytes. Also, Notepad++ is saying your code is actually 241 bytes long. I know 1 of those bytes is from the newline. But the other is a mistery to me. – Ismael Miguel Oct 23 '16 at 0:06

# ///, 182 180 bytes

/+/_____//*/# |
&//&/@@@@@|# //%/ |
\\\\++\\\/
//$/ ++ \\\/!\\\\ | //#/ //!/# //@/|!| /$2*2%$3*3%$4*4%$5*5%$6*6%$7*7%$8*8%$9*9%$10#|
@@@@@|#10 |
\\++\/
$J*J%$K*K%$Q*Q%$A*A%


Try it online!

-2 bytes thanks to m-chrzan

• You can save two bytes by having + substitute for only 5 _s, and then having two +s where you have single +s now. – m-chrzan Oct 21 '16 at 23:10

## Python 3.5, 110 bytes

u='_'*10
for c in[*range(2,11),*'JQKA']:print(' %s\n/%%11s\n'%u%'\\'+'| %-6s%2s |\n'*7%(c,*' '*12,c)+'\%s/'%u)


Prints

• The top two lines ' %s\n/%%11s\n'%u%'\\' where u is '_'*10
• The middle 7 lines '| %-2s %2s |\n', each of which has two string formatting slots. The first and last are filled with the card value, and the rest with spaces for no effect
• The bottom line '\%s/'%u

Python 3.5's new unpacking features are used in two places. The list of labels [*range(2,11),*'JQKA'] unpacks the numbers and letters into one list. And, the tuple (c,*' '*12,c) unpacks twelve entries of spaces into the center.

# Scala, 161 bytes

val a=" "*7
val u="_"*10
((2 to 10)++"JQKA")map(_+"")map{x=>val p=" "*(2-x.size)

# Ruby, 115 bytes

Fairly straightforward use of printf.

([*(?2.."10")]+%w{J Q K A}).map{|e|printf" #{u=?_*10}
/%11s
| %-9s|
#{(?|+' '*10+"|
")*5}|%9s |
\\#{u}/
",?\\,e,e}


## Racket 327 bytes

(let*((ms make-string)(p #\space)(e? equal?)(sa string-append)(f(λ(s)(display(sa" "(ms 10 #\_)" \n""/"(ms 10 p)"\\\n""| "s
(ms(if(e? s"10")7 8)p)"|\n"(apply sa(for/list((i 6))"|          |\n"))"| "(ms(if(e? s"10")6 7)p)s" |\n"
"\\"(ms 10 #\_)"/\n")))))(for((i(range 2 11)))(f(number->string i)))(for((i'("J""Q""K""A")))(f i)))


Ungolfed:

(define (main)
(let* ((ms make-string)
(e? equal?)
(sa string-append)
(f(lambda(s)
(display
(sa
" "
(ms 10 #\_)
" \n"
"/"
(ms 10 #\space)
"\\\n"
"| " s   (ms (if(e? s "10") 7 8) #\space)   "|\n"
(apply sa (for/list ((i 6)) "|          |\n"))
"| "  (ms (if(e? s "10") 6 7) #\space)  s " |\n"
"\\" (ms 10 #\_) "/\n")
))))
(for ((i(range 2 11)))
(f (number->string i)))
(for ((i '("J" "Q" "K" "A")))
(f i))
))


Testing:

(main)


Output:

 __________
/          \
| 2        |
|          |
|          |
|          |
|          |
|          |
|          |
|        2 |
\__________/
__________
/          \
| 3        |
|          |
|          |
|          |
|          |
|          |
|          |
|        3 |
\__________/
__________
/          \
| 4        |
|          |
|          |
|          |
|          |
|          |
|          |
|        4 |
\__________/
__________
/          \
| 5        |
|          |
|          |
|          |
|          |
|          |
|          |
|        5 |
\__________/
__________
/          \
| 6        |
|          |
|          |
|          |
|          |
|          |
|          |
|        6 |
\__________/
__________
/          \
| 7        |
|          |
|          |
|          |
|          |
|          |
|          |
|        7 |
\__________/
__________
/          \
| 8        |
|          |
|          |
|          |
|          |
|          |
|          |
|        8 |
\__________/
__________
/          \
| 9        |
|          |
|          |
|          |
|          |
|          |
|          |
|        9 |
\__________/
__________
/          \
| 10       |
|          |
|          |
|          |
|          |
|          |
|          |
|       10 |
\__________/
__________
/          \
| J        |
|          |
|          |
|          |
|          |
|          |
|          |
|        J |
\__________/
__________
/          \
| Q        |
|          |
|          |
|          |
|          |
|          |
|          |
|        Q |
\__________/
__________
/          \
| K        |
|          |
|          |
|          |
|          |
|          |
|          |
|        K |
\__________/
__________
/          \
| A        |
|          |
|          |
|          |
|          |
|          |
|          |
|        A |
\__________/


# Java 7, 287 bytes

String c(){String r="",l="__________",c=(" "+l+" \n/s\\\n| z       |\nxxxxxx|       y|\n\\"+l+"/\n").replace("x","|s|\n").replace("s","          ");for(int i=0;i++<13;r+=c.replace("z",i==10?"10":(l=i<2?"A ":i>12?"K ":i>11?"Q ":i>10?"J ":i+" ")).replace("y",i==10?"10 ":" "+l));return r;}


Ok, this is ugly and not very efficient, but it works.. That 10 as special case with a space before at the top and after at the bottom position really screws with everyone..

Ungolfed & test code:

Try it here.

class M{
static String c(){
String r = "",
l = "__________",
c = (" " + l + " \n/s\\\n| z       |\nxxxxxx|       y|\n\\" + l + "/\n")
.replace("x", "|s|\n")
.replace("s", "          ");
for(int i = 0; i++ < 13; r += c
.replace("z", i == 10
? "10"
: (l = i < 2
? "A "
: i > 12
? "K "
: i > 11
? "Q "
: i > 10
? "J "
: i+" "))
.replace("y", i == 10
? "10 "
: " "+l));
return r;
}

public static void main(String[] a){
System.out.println(c());
}
}


Output:

 __________
/          \
| A        |
|          |
|          |
|          |
|          |
|          |
|          |
|        A |
\__________/
__________
/          \
| 2        |
|          |
|          |
|          |
|          |
|          |
|          |
|        2 |
\__________/
__________
/          \
| 3        |
|          |
|          |
|          |
|          |
|          |
|          |
|        3 |
\__________/
__________
/          \
| 4        |
|          |
|          |
|          |
|          |
|          |
|          |
|        4 |
\__________/
__________
/          \
| 5        |
|          |
|          |
|          |
|          |
|          |
|          |
|        5 |
\__________/
__________
/          \
| 6        |
|          |
|          |
|          |
|          |
|          |
|          |
|        6 |
\__________/
__________
/          \
| 7        |
|          |
|          |
|          |
|          |
|          |
|          |
|        7 |
\__________/
__________
/          \
| 8        |
|          |
|          |
|          |
|          |
|          |
|          |
|        8 |
\__________/
__________
/          \
| 9        |
|          |
|          |
|          |
|          |
|          |
|          |
|        9 |
\__________/
__________
/          \
| 10       |
|          |
|          |
|          |
|          |
|          |
|          |
|       10 |
\__________/
__________
/          \
| J        |
|          |
|          |
|          |
|          |
|          |
|          |
|        J |
\__________/
__________
/          \
| Q        |
|          |
|          |
|          |
|          |
|          |
|          |
|        Q |
\__________/
__________
/          \
| K        |
|          |
|          |
|          |
|          |
|          |
|          |
|        K |
\__________/


# R, 175 bytes

for(x in c(2:10,"J","Q","K","A")){r=c("|"," ",x,rep(" ",9-nchar(x)),"|");cat(" __________ \n/          \\\n",r,"\n",rep("|          |\n",5),rev(r),"\n\\__________/\n",sep="")}


A fairly competitive answer in R this time for an ascii-art challenge and should definitely be golfable.

Try it on R-fiddle

Ungolfed and explained

for(x in c(2:10,"J","Q","K","A")){          # For each card in vector 1,...,10,J,Q,K,A
r=c("|"," ",x,rep(" ",9-nchar(x)),"|")  # Create variable for 3rd row called "r".
;cat(" __________ \n/          \\\n",   # Print: hardcoded top two rows,
r,"\n",                                 # 3rd row,
rep("|          |\n",5),                # Repeat middle section 5 times,
rev(r),                                 # Reversed 3rd row,
"\n\\__________/\n",                    # Hardcoded bottom row
sep="")                                 # Set separator to empty string
}


The most interesting aspect where a few bytes are saved is the assignment of the third row:

r=c("|"," ",x,rep(" ",9-nchar(x)),"|")


Because there are 8 spaces in total between the character denoting the card value and the final | (except for 10) we can repeat 9 spaces and subtract the number of characters in the currently printed card.

By storing each character in the 3rd row as its own element in the string vector r we can reverse the vector and reuse it for the 9th row.

# C#, 385 Bytes

My first ASCII Art challenge - it was fun!

Golfed:

string D(){var d=new string[15];for(int i=2;i<15;i++){var a=i>10?new Dictionary<int,string>(){{ 11,"J"},{12,"Q"},{13,"K"},{14,"A"},}[i]:i+"";var r="|          |";d[i]=string.Join("\n",new string[]{" __________",@"/          \",a.Length>1?"| "+a+"       |":"| "+a+"        |",r,r,r,r,r,a.Length>1?"|       " + a +" |" : "|        "+a+" |",@"\__________/"});}return string.Join("\n",d);}


Ungolfed:

public string D()
{
var d = new string[15];

for (int i = 2; i < 15; i++)
{
var a = i > 10 ? new Dictionary<int, string>() {
{ 11, "J" },
{ 12, "Q" },
{ 13, "K" },
{ 14, "A" },
}[i]
: i+"";

var r = "|          |";

d[i] = string.Join("\n", new string[] {
" __________",
@"/          \",
a.Length > 1 ? "| " + a + "       |" : "| " + a + "        |",
r,
r,
r,
r,
r,
a.Length > 1 ? "|       " + a +" |" : "|        " + a +" |",
@"\__________/"});
}

return string.Join("\n", d);
}


# Actually, 91 bytes

"JQKA"#9⌐2x+;k' ;'_9u*@++'\' 9u*'/++"| {:<9}|"5'|;' 9u*@++n"|{:>9} |"'/'_9u*'\++kp@'
jfMi


Try it online!

## Explanation

Part 1: setting up the list of face values:

"JQKA"#9⌐2x+PART 2 CODEMi
9⌐2x                  range(2,11) ([2, 10])
"JQKA"#    +                 extend with ["J", "Q", "K", "A"]
PART 2 CODEM   do Part 2 for each item in list
i  flatten resulting list and implicitly print


Part 2: creating the cards (newline replaced with \n for readability):

;k' ;'_9u*@++'\' 9u*'/++"| {:<9}|"5'|;' 9u*@++n"|{:>9} |"'/'_9u*'\++kp@'\njf
;k                                                                            duplicate the face value, push both copies to a list
' ;'_9u*@++                                                                 construct the top line
'\' 9u*'/++                                                      construct the second line
"| {:<9}|"                                            create a format string to place the value in a left-aligned 9-width field in the top left of the card, one space away from the edge
5'|;' 9u*@++n                               create 5 copies of the blank middle section
"|{:>9} |"                     like before, but right-align the face value
'/'_9u*'/++          construct the bottom of the card
kp@'\nj   push entire stack to a list, pop the list containing the face values out of that list, and join the rest (the card strings) with newlines
f  format the card with the face values