14
\$\begingroup\$

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!

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

18 Answers 18

10
\$\begingroup\$

PowerShell v2+, 120 116 114 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        |
...
\$\endgroup\$
  • 1
    \$\begingroup\$ It's a strange day when PowerShell is winning! Nice work :) \$\endgroup\$ – Kade Oct 21 '16 at 20:15
  • \$\begingroup\$ @Shebang Thanks! Sub-100 is so dang close, but not sure if I can make it. \$\endgroup\$ – AdmBorkBork Oct 21 '16 at 20:27
  • \$\begingroup\$ [shakes fist] you're beating me by 3 bytes. THREE BYTES!! \$\endgroup\$ – Gabriel Benamy Oct 22 '16 at 0:01
6
\$\begingroup\$

Python, 161 160 156 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+"/"
\$\endgroup\$
  • 2
    \$\begingroup\$ Holy Moly that was quick \$\endgroup\$ – jacksonecac Oct 21 '16 at 19:23
  • \$\begingroup\$ 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! \$\endgroup\$ – Kade Oct 21 '16 at 22:32
5
\$\begingroup\$

JavaScript (ES6), 151 bytes

f=
_=>`2345678910JQKA`.replace(/.0?/g,s=>` __________
/          \\
| `+(s+=`   `+s).slice(0,4)+`     |
|     `.repeat(6)+s.slice(-4)+` |
\\__________/
`)
;
document.write('<pre>'+f());

\$\endgroup\$
  • \$\begingroup\$ @Emigna Thanks, I forgot it in my other answer too. \$\endgroup\$ – Neil Oct 21 '16 at 20:10
4
\$\begingroup\$

Perl, 128 117 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.

\$\endgroup\$
  • \$\begingroup\$ 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 ()) \$\endgroup\$ – Ton Hospel Oct 21 '16 at 21:43
  • \$\begingroup\$ 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 :( \$\endgroup\$ – Gabriel Benamy Oct 21 '16 at 22:21
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – Ton Hospel Oct 22 '16 at 9:33
4
\$\begingroup\$

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;}
\$\endgroup\$
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Ismael Miguel Oct 23 '16 at 0:06
3
\$\begingroup\$

///, 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

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

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.

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

Scala, 161 bytes

val a=" "*7
val u="_"*10
((2 to 10)++"JQKA")map(_+"")map{x=>val p=" "*(2-x.size)
s" $u \n/$a   \\\n| $x$p$a|\n" + s"|$a   |\n" * 5 + s"|$a$p$x |\n\\$u/\n"}
\$\endgroup\$
2
\$\begingroup\$

Batch, 236 bytes

@echo off
for %%v in (2 3 4 5 6 7 8 9 10 J Q K A)do call:v %%v
exit/b
:v
set s=%1       %1
echo  __________
echo /          \
echo ^| %s:~0,8% ^|
for /l %%l in (1,1,5)do echo ^|          ^|
echo ^| %s:~-8% ^|
echo \__________/

I tried golfing this in three different ways but ended up with the same byte count each time...

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

05AB1E, 71 70 68 66 65 64 bytes

Uses CP-1252 encoding.

TL¦"JQKA"S«vð'_TשððT×…/ÿ\9yg-ð×y"| ÿÿ|"ÂðT×…|ÿ|5×sT‡®…\ÿ/JTä»,

Slightly modified link as doesn't work with ÿ on TIO atm.

Try it online!

Explanation

TL¦"JQKA"S« pushes the list [2,3,4,5,6,7,8,9,10,J,Q,K,A]

We then loop over each card value with v

ð'_Tשð constructs " __________ "
ðT×…/ÿ\ constructs "/ \"
9yg-ð×y"| ÿÿ|"Â constructs the 2 rows with card values (the second row is the first reversed)
ðT×…|ÿ|5× constructs 5 rows of the form "| |"

Then we

s     # move the 2nd card value row after the 5 "middle rows"
 T‡  # and replace 1 with 0 and vice versa

®…\ÿ/ constructs the bottom row

J       # join everything into 1 string
 Tä     # split into 10 parts
   »,   # merge by newline and print with newline
\$\endgroup\$
2
\$\begingroup\$

V, 87 bytes

i ±_ 
/± \Ypr|$.Y6P3|r2Lhhr2o\±_/
H8ñy}GP2j6j? _ñ2j$X6jxG"04p/9
rJn.nrQn,nrKn.nrAn.

Try it online!

Since this contains some unprintables, here is a hexdump:

0000000: 6920 b15f 200a 2fb1 205c 1b59 7072 7c24  i ._ ./. \.Ypr|$
0000010: 2e59 3650 337c 7232 4c68 6872 326f 5cb1  .Y6P3|r2Lhhr2o\.
0000020: 5f2f 0a1b 4838 f179 7d47 5032 6a01 366a  _/..H8.y}GP2j.6j
0000030: 013f 205f f132 6a24 5836 6a78 4722 3034  .? _.2j$X6jxG"04
0000040: 702f 390a 724a 6e2e 6e72 516e 2c6e 724b  p/9.rJn.nrQn,nrK
0000050: 6e2e 6e72 416e 2e                        n.nrAn.
\$\endgroup\$
2
\$\begingroup\$

PHP, 135 131 158 134 bytes

Hopefully, I can find a way to shorten this a little more.

foreach([2,3,4,5,6,7,8,9,10,J,Q,K,A]as$C)printf(" %'_9s
/%12s| %-8s|%s
|%8s |
\\%'_9s/
",_,'\
',$C,str_repeat('
|         |',5),$C,_);

This takes advantage of printf to repeat multiple characters and format everything nicely.


Old version:

Not exactly a piece of beauty, but works!

$L=__________;$S='        ';foreach([2,3,4,5,6,7,8,9,10,J,Q,K,A]as$C)echo" $L
/  $S\
| $C".($P=substr($S,$C>9))."|
",str_repeat("|  $S|
",5),"|$P$C |
\\$L/
";

Thanks to Jörg Hülsermann for detecting a bug and for letting me use part of his code, that reduced it by 4 bytes! And for finding a fatal bug.

\$\endgroup\$
  • \$\begingroup\$ The 10 looks strange. I believe you must do extra work \$\endgroup\$ – Jörg Hülsermann Oct 22 '16 at 22:36
  • \$\begingroup\$ @JörgHülsermann You're right. The 10 is bugged. Is it alright if I use your array? Using [2,3,4,5,6,7,8,9,10,J,Q,K,A] instead of that split saves me 4 bytes. If you don't authorize it, I will understand. \$\endgroup\$ – Ismael Miguel Oct 22 '16 at 22:45
  • \$\begingroup\$ Take it. You have make the better way in PHP and I support all what you need. \$\endgroup\$ – Jörg Hülsermann Oct 22 '16 at 22:54
  • \$\begingroup\$ @JörgHülsermann Thank you. I am looking at your answer and I'm finding some places where to shave off some bytes. \$\endgroup\$ – Ismael Miguel Oct 22 '16 at 23:38
  • \$\begingroup\$ Instead of $C$S $C".($P=substr($S,$C>9))." to handle the spaces with value 10 and instead of $S$C you need then $P$C \$\endgroup\$ – Jörg Hülsermann Oct 23 '16 at 0:34
1
\$\begingroup\$

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}
\$\endgroup\$
1
\$\begingroup\$

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 |
\__________/
\$\endgroup\$
1
\$\begingroup\$

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 |
\__________/
\$\endgroup\$
1
\$\begingroup\$

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.

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

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);
}
\$\endgroup\$
1
\$\begingroup\$

Actually, 91 bytes

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

Try it online!

Explanation

Part 1: setting up the list of face values:

"JQKA"#9⌐2x+`PART 2 CODE`Mi
       9⌐2x                  range(2,11) ([2, 10])
"JQKA"#    +                 extend with ["J", "Q", "K", "A"]
            `PART 2 CODE`M   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
\$\endgroup\$

Your Answer

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

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