很久以前,当我用通常的扑克牌编码纸牌游戏时,我通常会为每一张牌指定一个号码,然后调用一个函数来得到一张卡片。这在某种程度上激励了我提出这个挑战。
因此,对于那些不知道扑克牌的人来说,一副牌由52张牌组成(四套牌中每套13张,即红心牌、钻石牌、黑桃牌、棍棒)。在每套西装中,有13张牌--首先是2-10的牌号,然后是杰克(J)、皇后(Q)、国王(K)和Ace(A)。这是命令
挑战是以1-52之间的整数作为输入,并在该位置显示卡片。但是,你的输出必须是文字。此外,必须维持秩序,即前13张牌是红心牌,然后是钻石牌,然后是黑桃牌,最后是棍棒牌。
例如,如果有人选择数字30.The卡,则属于第三套,即黑桃。此外,这将是西服中的第四张卡,这意味着数字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这是密码-高尔夫,所以最短的代码获胜。
发布于 2018-03-14 08:07:17
发布于 2018-03-14 08:50:57
itwo.three.four.five.six.seven.eight.nine.ten.jack.queen.king.ace.i 13 of hearts.diamonds.spades.clubs.➗i 130索引。在网上试试!
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⌋发布于 2018-03-14 12:21:27
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()]从STDIN获取输入(1-索引)并使用source(...,echo=T)将结果打印到控制台。
它不是很漂亮,但它比我使用outer的最佳解决方案短了2个字节(如下所示),所以让我们来提醒您检查另一种方法吧!
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.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()]本质上和上面一样;然而,outer会正确地进行回收,但是必须为paste设置sep=" of "使这个过程变得更长。
https://codegolf.stackexchange.com/questions/158060
复制相似问题