是哪张卡?


30

介绍

很久以前,当我习惯用普通纸牌对纸牌游戏进行编码时,我曾经为每张纸牌指定一个数字,然后调用带有某个数字的函数来获得一张纸牌。这在某种程度上启发了我去挑战。

因此,对于不了解扑克牌的人来说,一副纸牌由52张纸牌组成(四种花色中的每套13张,即红心,钻石,黑桃,球杆)。每套西装中有13张牌-首先是2-10的牌,然后是Jack(J),Queen(Q),King(K)和Ace(A)。这是命令

挑战

挑战是取1-52之间的整数作为输入并在该位置显示卡。但是,您的输出必须以语言显示。同样,必须保持顺序,即前13张将是红心,然后是钻石,然后是黑桃,最后是俱乐部。

例如,如果有人选择该号码,则30该牌将属于第三套,即黑桃。同样,它将是西装中的第四张牌,即数字5。因此,您的文字输出必须是:five of spades并且应始终遵循此格式,即,首先是该牌,然后是of和,其名称为最后,中间留有所需的空格。

输入输出

输入将是 介于1到52之间(包括两者之间)的整数。请注意,此处的计数从1开始。您可以选择从0开始。但是,您必须维持订单卡。您的输出应该是用文字写在那个位置的卡片。您不需要处理无效的输入。另外,您的输出可能是小写或大写。

以下是所有可能的输入及其输出的列表:

1 -> two of hearts
2 -> three of hearts
3 -> four of hearts
4 -> five of hearts
5 -> six of hearts
6 -> seven of hearts
7 -> eight of hearts
8 -> nine of hearts
9 -> ten of hearts
10 -> jack of hearts
11 -> queen of hearts
12 -> king of hearts
13 -> ace of hearts
14 -> two of diamonds
15 -> three of diamonds
16 -> four of diamonds
17 -> five of diamonds
18 -> six of diamonds
19 -> seven of diamonds
20 -> eight of diamonds
21 -> nine of diamonds
22 -> ten of diamonds
23 -> jack of diamonds
24 -> queen of diamonds
25 -> king of diamonds
26 -> ace of diamonds
27 -> two of spades
28 -> three of spades
29 -> four of spades
30 -> five of spades
31 -> six of spades
32 -> seven of spades
33 -> eight of spades
34 -> nine of spades
35 -> ten of spades
36 -> jack of spades
37 -> queen of spades
38 -> king of spades
39 -> ace of spades
40 -> two of clubs
41 -> three of clubs
42 -> four of clubs
43 -> five of clubs
44 -> six of clubs
45 -> seven of clubs
46 -> eight of clubs
47 -> nine of clubs
48 -> ten of clubs
49 -> jack of clubs
50 -> queen of clubs
51 -> king of clubs
52 -> ace of clubs

计分

这是,因此最短的代码获胜。


1
西装的默认顺序通常不是心形,空格,菱形,球杆(红色,黑色,红色,黑色)。挑战并不重要,只是想知道为什么要按顺序进行。
凯文·克鲁伊森

3
它因游戏而异。不同的游戏遵循不同的顺序。在谈论纸牌时,有些游戏甚至将王牌作为西装中最低的纸牌。
Manish Kundu

我可以输出two\s\s\sof\shearts其中\s代表一个空间?(请注意两个额外的空间。)
完全人类的

2
@totallyhuman抱歉,但两者之间必须恰好有1个空格
Manish Kundu

Answers:


31

Python 3中 115个  90字节

from unicodedata import*
lambda n:name(chr(n%13+n%13//11+[6,0,4,2][-n//13]*8+127137))[13:]

一个未命名的函数,以大写形式返回字符串。

在线尝试!

怎么样?

Unicode字符具有名称。其中一些的名称类似于“两张扑克牌”,因此我们可以获得代表所需卡的Unicode字符,并去除前13个字符以获取输出。

感兴趣的Unicode字符位于一个块内,如下所示:

            0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F
U+1F0Ax     x   As  2s  3s  4s  5s  6s  7s  8s  9s  Ts  Js  x   Qs  Ks  x
U+1F0Bx     x   Ah  2h  3h  4h  5h  6h  7h  8h  9h  Th  Jh  x   Qh  Kh  x
U+1F0Cx     x   Ad  2d  3d  4d  5d  6d  7d  8d  9d  Td  Jd  x   Qd  Kd  x
U+1F0Dx     x   Ac  2c  3c  4c  5c  6c  7c  8c  9c  Tc  Jc  x   Qc  Kc  x                           

哪里x不是我们所追求的字符(C栏是“骑士”;三是在F有“王牌”之一0是通用的;其余的都保留字符)。

这样我们可以添加 一些值到0x1F0A1 = 127137(As)以查找所需的卡。

要添加的值仅因以下三点而复杂:

  1. 我们需要对西服重新排序(从s,h,d,c到h,d,s,c)
  2. 我们需要将等级从(A,2,...,K重新排序为2,...,K,A)
  3. 我们需要避免没有感兴趣的卡片的列。

使用one-indexing选项可允许使用负整数除法来索引行偏移量数组,以使用[6,0,4,2][-n//13]*8+(有效[48,0,32,16][-n//13])对西装进行重新排序,然后我们也可以将ace放在正确的位置,n%13+然后避免Cn%13//11+(有效(n%13>10)+)列中的骑士。


就像我开始这样的答案一样(我确定我的答案会更长),我瞥了一眼,看到了你的答案。好东西。
mbomb007 '18

...还有另一个字节要打高尔夫球:)
乔纳森·艾伦

13

Perl6 / Rakudo 70字节

索引0

使用perl6 -pe,并且没有字典压缩:

chr('🂱🃁🂡🃑'.ords[$_/13]+($_+1)%13*1.091).uniname.substr(13)

它只是以Unicode(从Ace开始)查找卡,询问名称并使用它。这与乔纳森·艾特肯(Jonathan Aitken)的Python答案类似(尽管我当时还不知道!) -仅我从所有4个A中索引,而不是从黑桃A中获得4个偏移量,然后乘以1.091就可以建立索引舍弃Unicode中的Knight条目。

查看所有输出(输入值0到51)https://glot.io/snippets/ez5v2gkx83

编辑以应付Unicode牌组中的Knights,因为Unicode。

Perl6♥Unicode


@JonathanAllan:它使用4张基本卡来设置顺序(它们在必需的西装顺序中),但是在骑士团中很常见-我没有注意到。固定为几个字符。
Phil H

@JonathanAllan:其他答案的计数中有一些不正确之处-每个人在表示字符时都说“字节”。受到压迫的人是最残酷的罪犯。
Phil H

3
我认为您会发现带有包含以Unicode形式表示的压缩字符串的压缩文件实际上具有自己的代码页(对于Jelly,Husk,Charcoal和05AB1E肯定是正确的)。
乔纳森·艾伦,

谢谢,我一点都不欣赏。
Phil H

@PhilH如果您怀疑字节数是否正确,可以要求他们提供一个十六进制转储。
user202729 '18

9

05AB1E,54个字节

0索引

“»€Å‹¡Šdesž…“#“‚•„í†ìˆÈŒšï¿Ÿ¯¥Š—¿—ÉŸÄ‹ŒÁà“#âí" of "ýsè

在线尝试!

说明

“»€Å‹¡Šdesž…“#                                          # push list of suits
              “‚•„í†ìˆÈŒšï¿Ÿ¯¥Š—¿—ÉŸÄ‹ŒÁà“#             # push list of ranks
                                           â            # cartesian product
                                            í           # reverse each
                                             " of "ý    # join on " of "
                                                    sè  # index into cardlist with input

@PhilH 05AB1E使用一个代码页,PPCG上大多数高尔夫语言的答案也都使用此代码
-dzaima

抱歉,没有意识到这是如此普遍。
Phil H

@PhilH嗯,许多人所做的完全相同,只是认为所显示的unicode实际上就是提交分数。但是,我希望始终在标题中超链接代码页(例如在我的SOGL答案上)是否是标准的
dzaima

@dzaima:我做了一段时间,但是我仍然收到评论,所以我停了下来。但是我同意,如果将它包含在TIO模板中会很好。
Emigna

大声笑,我没看这个答案... “»€Å‹ spadesž…“#"of "ì“‚•„í†ìˆÈŒšï¿Ÿ¯¥Š—¿—ÉŸÄ‹ŒÁà“#âí»- 54个字节的!
魔术章鱼缸

6

Python 2中167 148字节的

n=input();print 'two three four five six seven eight nine ten jack queen king ace'.split()[n%13]+' of '+['hearts','diamonds','spades','clubs'][n/13]

零索引。

在线尝试!

编辑:冒泡者使用split方法(并提供较短的答案)提出了一个很好的观点。在第二个块上,使用split()产生相同的字节数。


Welcome! By default submissions must handle input and output; see the Python rules summary.
xnor

Got it, thanks for pointing out!
PHC

1
141 bytes with lambda and split. Tried interleaving the chars for [n%13::13]or something, but no luck.
Bubbler

Thanks for making me realize that split would save some bytes. Another byte goes away with Python2's default integer division.
PHC

4
140 bytes using percent notation to factor out s; xnor pointed it out in chat.
Bubbler

6

R, 154 bytes

paste(el(strsplit("Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King,Ace",",")),"of",rep(c("Hearts","Diamonds","Spades","Clubs"),e=13))[scan()]

Try it online!

Takes input (1-indexed) from STDIN and with source(...,echo=T) will print the result to console.

It's not pretty, BUT it comes in 2 bytes shorter than the best solution I could using outer (presented below), so let this be a reminder to examine another approach!

paste(                          # concatenate together, separating by spaces,
                                # and recycling each arg to match the length of the longest
el(strsplit("Two,...",",")),    # split on commas and take the first element
"of",                           # 
 rep(c("Hearts",...),           # replicate the suits (shorter as a vector than using strsplit
               e=13)            # each 13 times
                    )[scan()]   # and take the input'th index.

R, 156 bytes

outer(el(strsplit("Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King,Ace",",")),c("Hearts","Diamonds","Spades","Clubs"),paste,sep=" of ")[scan()]

Try it online!

Essentially the same as above; however, outer will do the recycling properly, but having to set sep=" of " for the paste made this just a hair longer.


6

Emojicode, 202 bytes

🍇i🚂😀🍪🍺🐽🔫🔤two.three.four.five.six.seven.eight.nine.ten.jack.queen.king.ace🔤🔤.🔤🚮i 13🔤 of 🔤🍺🐽🔫🔤hearts.diamonds.spades.clubs🔤🔤.🔤➗i 13🍪🍉

0 indexed. Try it online!

Explanation:

🍇		start of the closure block
  i🚂		 closure takes an integer argument i
  😀		 print:
    🍪		  concatenate these strings:
      🍺🐽🔫🔤...🔤🔤.🔤🚮i 13  [a]
      🔤 of 🔤
      🍺🐽🔫🔤...🔤🔤.🔤➗i 13  [b]
    🍪
🍉

[a]:
🍺		tell Emojicode to dereference without checking
🐽		 get the nth element of the following array
  🔫		  create an array using the following string and separator
    🔤...🔤
    🔤.🔤
  🚮 i 13	n, i mod 13

[b]
🍺🐽🔫🔤...🔤🔤.🔤➗i 13
same but with ⌊i÷13⌋

10
Somehow it seems right that "dereferencing without checking" is a mug of beer.
maxathousand

6

Excel, 156 bytes

=TRIM(MID("two  threefour five six  seveneightnine ten  jack queenking ace",1+MOD(A1,13)*5,5))&" of "&CHOOSE(1+(A1/13),"hearts","diamonds","spades","clubs")

Cards from 0-51. Unfortunately, Excel does not feature a function to convert 1 to "one"...

Using TRIM and MID is shorter than using CHOOSE for the face values, but longer than using CHOOSE for the Suit.


Clever with the MID() and combining the words!
BruceWayne

5

Java 8, 141 bytes

n->"two;three;four;five;six;seven;eight;nine;ten;jack;queen;king;ace".split(";")[n%13]+" of "+"hearts;diamonds;spades;clubs".split(";")[n/13]

Input is 0-indexed.

Explanation:

Try it online.

n->         // Method with integer parameter and String return-type
  "two;three;four;five;six;seven;eight;nine;ten;jack;queen;king;ace".split(";")[n%13]
            //  Take `n` modulo-13 as 0-indexed card value
   +" of "  //  append " of "
   +"hearts;diamonds;spades;clubs".split(";")[n/13]
            //  append `n` integer-divided by 13 as 0-indexed suit

4

Kotlin, 154 152 140 bytes

i->"two,three,four,five,six,seven,eight,nine,ten,jack,queen,king,ace".split(',')[i%13]+" of ${"heart,diamond,spade,club".split(',')[i/13]}s"

Try it online!

Updated to use just lambda expression.


That's completely fine.
Nissa

2
Welcome to PPCG! I was discouraged by the golfing languages at first, but then somewhere someone told me "It's really the best answer in each language wins" and I realized it was a competition against other (your lang here) golfers. Keep it up, and I hope you enjoy your time here.
Giuseppe

Lambdas in Kotlin (unlike Java) always have a leading { and a trailing }. So maybe you should include and count them in your solution?
Roland Schmitz

3

JavaScript ES6, 124 118 Bytes, 0-index

F= x=>(h=btoa`O
?NÞ{ñhº¿Å÷¿J,IëÞñ"6)Þý7§üô.yéÿ*)àüÿÿÿæ«·÷bjj'wû)i׿r[`.split`/`)[x%13]+` of ${h[x/13|16]}s`

console.log (F(51))

Base64 version

eD0+KGg9YnRvYWBPCj9OGt578Wi6v8WK979KLH9J696f8SKCG382Kd79N6f8lpyT9C556f8qKeD8Bx7///+F5qu392Jqaid3+ylp179yW5tgLnNwbGl0YC9gKVt4JTEzXStgIG9mICR7aFt4LzEzfDE2XX1zYA==

online test seems broken
l4m2

does not work in chrome
Luis felipe De jesus Munoz

works on Firefox @Luis felipe De jesus Munoz
l4m2

Your 118 byte version measures 107 chars 136 bytes here: mothereff.in/byte-counter
Phil H

1
@PhilH if you decode the given base64 of the code to a list of bytes (e.g. using this), you'll see that it actually results in the mentioned 118 bytes.
dzaima

3

Stax, 58 57 56 bytes

î↑à■?R╢8«E▄¡╔ÿ•L╫<<⌠ï∞∟⌡♪Ös1"TàLα╥▀¢¡◄└%≈δñM;;}'░o=⌡»╬í√

Run and debug it

Here's the commented ungolfed representation of the same program. It uses stax's compressed literals heavily. The input is 0-indexed. It's Emigna's 05AB1E algorithm.

`SsUI'S~pTU5T@T^Ez+`j   suits
`fV:l7eTkQtL*L2!CZb6u[&YNO4>cNHn;9(`j   ranks
|*  cross-product
@   index with input
r   reverse pair
`%+(`*  join with " of "

Run this one


3

Bash, 133 bytes

V=(two three four five six seven eight nine ten jack queen king ace hearts diamonds spades clubs)
echo ${V[$1%13]} of ${V[$1/13+13]}

Choosing to use 0 based as per the option given, supporting 0 (two of hearts) through 51 (ace of clubs)


Welcome to PPCG!
Martin Ender

3

Husk, 52 bytes

;↔!Πmw¶¨×‼sÿẋδẎ₆ṡ⁷Ḃ6‰fωθ»&⌈θƒV₆x⁵▼Ëġ`nıEṅ'jĊk⁸"eïkÄc

Try it online!

I'm always happy to show off Husk's string compression system :D

Explanation

The majority of the program (from ¨ onwards) is obviously a compressed string. When uncompressed it turns into:

hearts diamonds spades clubs
of
two three four five six seven eight nine ten jack queen king ace

The program then is:

;↔!Πmw¶¨…
       ¨…    The previous string
      ¶      Split on lines
    mw       Split each line into words
             - we now have a list of lists of words
   Π         Cartesian product of the three lists
             - with this we obtain all possible combinations of suits and values
               with "of" between the two (e.g. ["spades","of","king"])
  !          Pick the combination at the index corresponding to the input
 ↔           Reverse it, so words are in the correct order
;            Wrap it in a list. Result: [["king","of","spades"]]

There are a couple of things left to explain:

  • We build the cards with suits before values because of how the cartesian product Π works: if we did it the other way around, the list of cards would be ordered by value (i.e. two of hearts, two of diamonds, two of spades, two of clubs, three of hearts...). As a consequence, we have to reverse our result.

  • The result of the program is a two-dimensional matrix of strings. This is automatically printed by Husk as a single string built by joining rows of the matrix with newlines and cells with spaces. The reason we build this matrix instead of using the more straightforward w (join a list of words with spaces) is that if using w the type inferencer guesses another interpretation for the program, producing a different result.


2

mIRCScript, 157 bytes

c echo $token(ace two three four five six seven eight nine ten jack queen king,$calc(1+$1% 13),32) of $token(clubs spades diamonds hearts,$calc(-$1// 13),32)

Load as an alias, then use: /c N. mIRC is 1-indexed, so floor division (//) on the negative value of the input produces -1 to -4 as required.


2

C (gcc), 148 bytes

f(n){printf("%.5s of %.7ss","two\0 threefour\0five\0six\0 seveneightnine\0ten\0 jack\0queenking\0ace"+n%13*5,"heart\0 diamondspade\0 club"+n/13*7);}

Try it online!

0-based.


You should be able to save 10 bytes by replacing the \0 with literal null bytes.
caird coinheringaahing

2

Haskell, 132 bytes

(!!)[v++" of "++s|s<-words"hearts diamonds spades clubs",v<-words"two three four five six seven eight nine ten jack queen king ace"]

Try it online!

An anonymous function, using list comprehension to build all the combinations of suit and value, and indexing into the resulting list with the input.


2

F#, 174 168 bytes

Removed some extra whitespace as noted by Manish Kundu. Thanks!

let c x=["two";"three";"four";"five";"six";"seven";"eight";"nine";"ten";"jack";"queen";"king";"ace"].[(x-1)%13]+" of "+["hearts";"diamonds";"spades";"clubs"].[(x-1)/13]

Try it online!

I'll be honest - I'm new at code golf, so I don't know if it's more appropriate to answer with a pure function like this (with parameters, but no I/O) or with a working code block with user I/O.


1
-4 bytes by only removing un-necessary spaces
Manish Kundu

The whitespace completely got past me. Well spotted! Thanks very much!
Ciaran_McCarthy

2

Octave, 155 153 151 150 bytes

@(x)[strsplit(' of ,s,heart,diamond,spade,club,ace,two,three,four,five,six,seven,eight,nine,ten,jack,queen,king',','){[mod(x,13)+7,1,ceil(2+x/13),2]}]

Try it online!

This creates a string starting with ' of ' and 's', then all the suits followed by all the ranks. This string is split at commas into separate strings. The suits are before the ranks, because since that saves a byte when creating the indices. After this, we index it using square brackets with the following indices:

{[mod(x,13)+7,1,ceil(2+x/13),2]}

which is the rank, followed by the first element ' of ', followed by the suit, followed by 's'.

Having the 's' as part of the suits (hearts,diamonds,spades,clubs) instead of a separate string is the exact same length but less fun.

Splitting on the default separator would save 4 bytes in the strsplit-call, but the spaces around ' of ' would be removed and would have to be added manually, costing more bytes.


2

V, 154 147 144 142 Bytes

-7 Bytes thanks to DJMcMayhem

13i1heart
2diamond
3spade
4club
ÚGxCtwo
three
four
five
six
seven
eight
nine
ten
jack
queen
king
aceH$A of 012j$d4ñ13jPñÍ «/ 
{ÀjYHVGpAs

Try it online!

Hexdump:

00000000: 3133 6931 6865 6172 740a 3264 6961 6d6f  13i1heart.2diamo
00000010: 6e64 0a33 7370 6164 650a 3463 6c75 620a  nd.3spade.4club.
00000020: 1bda 1647 7843 7477 6f0a 7468 7265 650a  ...GxCtwo.three.
00000030: 666f 7572 0a66 6976 650a 7369 780a 7365  four.five.six.se
00000040: 7665 6e0a 6569 6768 740a 6e69 6e65 0a74  ven.eight.nine.t
00000050: 656e 0a6a 6163 6b0a 7175 6565 6e0a 6b69  en.jack.queen.ki
00000060: 6e67 0a61 6365 1b16 4824 4120 6f66 201b  ng.ace..H$A of .
00000070: 3016 3132 6a24 6434 f131 336a 50f1 cd20  0.12j$d4.13jP.. 
00000080: ab2f 200a 7bc0 6a59 4856 4770 4173       ./ .{.jYHVGpAs

Here's the sort-shortcut: Try it online! Always happy to see someone new use V :)
DJMcMayhem

Here's some tips: 1) « == \+ 2) 12dj == 13D
DJMcMayhem

Thanks! :) And how do I use ò? I tried ò13j0Pò instead of 4ñ13j0Pñ, but that didn't terminate
oktupol

I actually tried that too. I'm not sure why it doesn't terminate. Maybe it's because it doesn't hit the bottom because the P adds new lines? Also, are you sure you need the 0 in that part? It seems to me like it would probably work without
DJMcMayhem

Oh, that's indeed the case. And you're right, the 0 is unnecessary
oktupol

2

C#, 219 207 202 197 bytes (0 indexed)

static string O(int i){string[]s={"two","three","four","five","six","seven","eight","nine","ten","jack","queen","king","ace","hearts","diamonds","spades","clubs"};return s[i%13]+" of "+s[i/14+13];}

thanks to input from @Ciaran_McCarthy and @raznagul

Takes an input of int I, subtracts 1 to match 0 indexing of the string array and outputs the number based on I mod 13 and the suit based on i/14+13.

works pretty well for my second code golf, just wondering if i could get it shorter using LINQ or something else.


2
Down to 200 by removing the i--; and doing --i in the first array index instead (i gets decremented before the modulo, and stays like that for the following division), removing the ,"of" in the array (it's not needed?), and removing the brackets around the return statement and adding one whitespace between return and s[...
Ciaran_McCarthy

1
The challenge allows the input to be 0-indexed so the i++ can be removed completely. By converting the function to a lambda I got it down to 178 bytes.
raznagul

2
Initally I came up with an answer for 163 bytes (see link above). I decided to not post it, because a 1 to 1 port of @KevinCruijssens Java answer will still be shorter. Maybe later I try to come up with a Linq answer just for the sake of having one. But I doubt it will be shorter. Especially because Linq starts with a 18 byte deficit for the using-Statement. Anyway +1 from me.
raznagul

Thanks to both Ciaran_McCarthy an raznagul for your input, got it down to 202 now, let me know if you see anything else that can be additionally golfed
James m

1
You still have the superfluous "of" in the array.
raznagul

2

PowerShell, 207 192 182 174 165 163 161 157 bytes

0-Indexed

$args|%{(-split'two three four five six seven eight nine ten jack queen king ace')[$_%13]+' of '+('hearts','diamonds','spades','clubs')[$_/13-replace'\..*']}

Try it online!

4 bytes saved thanks to AdmBorkBork in the comments


You can unary -split on whitespace to save 6 bytes -split'two three four five six seven eight nine ten jack queen king ace' and another byte using inline replace instead of floor $_/13-replace'\..*'
AdmBorkBork

@AdmBorkBork Thanks for the tips! How are you getting 6 bytes from changing -split? I only see savings of 3 bytes. It seems to still need the parentheses, so I am just removing the ',' and re-ordering the rest.
Nik Weiss

I'm not sure how I came up with 6, it is indeed only a savings of 3, lol.
AdmBorkBork

1

CJam, 114 bytes

riDmd"two three four five six seven eight nine ten jack queen king ace"S/=" of "@"hearts diamonds spades clubs"S/=

Try it online!

Zero-indexed. Will probably be beaten by languages with dictionary compression, but oh well...



1

Julia 0.6, 156 bytes

f(n)=print(split(" of ,hearts,diamonds,spades,clubs,two,three,four,five,six,seven,eight,nine,ten,jack,queen,king,ace",',')[[(n-1)%13+6,1,div(n-1,13)+2]]...)

Try it online!

-2 bytes thanks to @Stewie Griffin


1

Haskell, 144 bytes

f n=words"two three four five six seven eight nine ten jack queen king ace"!!(n`mod`13)++" of "++words"hearts diamonds spades clubs"!!(n`div`13)

Try it online!

This hits all kinds of Haskell's pain points.



1

Javascript 149 143 140 bytes

a=_=>"two three four five six seven eight nine ten jack queen king ace".split` `[_%13]+' of '+["hearts","diamonds","spades","clubs"][_/13|0]

-3 bits thanks to @rick hitchcock

a=_=>"two three four five six seven eight nine ten jack queen king ace".split` `[_%13]+' of '+["hearts","diamonds","spades","clubs"][_/13|0]
console.log(a(14))
console.log(a(34))
console.log(a(51))
console.log(a(8))
console.log(a(24))


1
Save 3 bytes by not splitting the second array, and by indexing it with [_/13|0]. For example: ["hearts","diamonds","spades","clubs"][_/13|0]
Rick Hitchcock

I don't think you need the a= since your function isn't recursive.
Oliver

1

Perl 5 -p, 119 bytes

0-based

$_=(TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,JACK,QUEEN,KING,ACE)[$_%13].' OF '.(HEART,DIAMOND,SPADE,CLUB)[$_/13].S

Try it online!


1

Japt, 91 86 bytes

0-indexed.

I used a tool written by @Shaggy to generate the compressed lists.

`{`twodÈ(‚fÆfivÀ£xç P ightdÍÂdȈjackdquÁÈkˆg»­`qd gU}  {`Ê#tsk¹aÚˆäi£kclubs`qk gUzD

Try it online!

Explanation:

The first compressed string contains the card values delimited by d. The second compressed string contains the card ranks delimited by k.

These chars were picked using Shaggy's tool, which generates a string delimited by a char that is optimally compressed using shoco (the compression that Japt uses). This allows us to create a list of card values and ranks.

We use backticks ` to decompress these strings, then we split the string using q, followed by the char to split on.

Once we have the lists, we map through the card values, then we get the index of the input. It is important to note that Japt wraps its indexes, so we don't have to modulo by 13.

At each item, we loop through the card ranks. We get the index by dividing the input by 13.

Once we have both items, we concatenate them with " of ", which produces the final string.


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.