中秋赌博游戏


11

明天是中秋节,本着节日的精神,我将介绍我们(厦门人)在节日期间玩的赌博游戏!

规则

游戏中有六个6面骰子。不同的数字组合具有不同的等级,特别强调四和一。您的工作是编写给定6个骰子的等级的手的程序/函数。以下是排名(我对规则进行了一些修改/简化):

等级

我猜只有中国人可以挑战!好的,这是一些英文说明。

  • 0:4个四和2个。
  • 1:6。
  • 2:6个
  • 3:除4和1之外的任何形式的6。
  • 4:5
  • 5:除了四分之一以外的任何形式的5。
  • 6:4
  • 7:直 (1-6)
  • 8:3
  • 9:4以外的任何一种。
  • 10:2
  • 11:1四。
  • 12:没事

输入值

6个数字,6个数字的数组或6个数字的字符串,它们代表1-6个骰子掷骰的值

输出量

您的程序/函数可以返回/输出任何东西来指示等级,只要每个等级由一个输出指示,反之亦然。例如 使用数字0-12、1-13等。

示例(使用0-12作为输出)

[1,1,1,1,1,1]->2
[1,4,4,4,1,4]->0
[3,6,5,1,4,2]->7
[1,2,3,5,6,6]->12
[3,6,3,3,3,3]->5
[4,5,5,5,5,5]->5

这是代码高尔夫球,因此最短的字节数为准!


(我会把它放在沙盒中,但我希望时机正确。我试图尽可能地透彻,请让我知道是否需要任何澄清。)
Quintec

@Shaggy因此,OP表示改为输出0-12或1-13
Shieru Asakoto

@Shaggy如我在问题中所述,输出不一定必须与标签号相对应。图像中跳过的数字和随机间隙将稍微简化规则-对于这种传统,确实没有确定的规则,这只是我的解释。
Quintec'Sep

不应该[1,2,3,5,6,6]->13吗??
J.Doe

@ J.Doe示例/测试用例使用索引作为结果而不是值。与值不同,10不会跳过。
凯文·克鲁伊森

Answers:


2

木炭,55字节

≡⌈Eθ№θι⁶I⁻²⌕14§θχ⁵I⁻⁵⁼⁵№θ4⁴⎇⁼№θ4⁴§60⁼№θ1²9¹7I⁻¹²⌊⊘X²№θ4

在线尝试!链接是详细版本的代码。不跳过10。说明:

≡⌈Eθ№θι

计算任何数字的最高频率。

⁶I⁻²⌕14§θχ

如果有一个6,14则从2中减去数字在字符串中的位置。这将导致1表示6 4s,2表示6 1s,3表示6。

⁵I⁻⁵⁼⁵№θ4

如果有一个5​​,那么除非有5 4s,否则结果为5,在这种情况下,将减去1。

⁴⎇⁼№θ4⁴§60⁼№θ1²9

如果有一个4,则如果有4 4,则结果为6,除非有2 1,在这种情况下,结果为0,否则结果为9。

¹7

如果所有数字都不相同,则结果为7。

I⁻¹²⌊⊘X²№θ4

否则结果为12-(4 >>(3-#of 4s))。


接受最短的答案似乎是最佳实践,因此我将这样做:)不幸的是,没有多少人看到并支持您的答案……
Quintec

@Quintec没问题;人们应该基于算法的独创性或其他使他们欣赏答案的因素来推荐答案。
尼尔

10

JavaScript(ES6),88个字节

a=>a.map(o=n=>[x=o[n]=-~o[n],6,,,21,9,8^o[1]][a=x<a?a:x])[5]|[,1,4,5,o[1]&2|8,2,4][o[4]]

在线尝试!测试所有可能的卷!

根据以下映射输出整数:

 Rank | Output       Rank | Output
------+--------     ------+--------
   0  |  31            7  |   7
   1  |  12            8  |   5
   2  |  14            9  |  21
   3  |   8           10  |   4
   4  |  11           11  |   1
   5  |   9           12  |   0
   6  |  29

怎么样?

方法

通过在以下之间执行按位或运算来计算输出:

  • F
  • 中号

例外情况:

  • F=44b4一种
  • 中号=66b6一种

F中号

F01个234一种4b56中号要么01个45810241个667671414662001个45810243001个458102442121212121293123215999131391111136一种889121381010126b141415141514141414

中号3中号3中号F=3

中号=1个F=1个

6 要么 1个=7

77

已评论

a =>                   // a[] = input array, reused as an integer to keep track of the
  a.map(               //       maximum number of occurrences of the same dice (M)
    o =                // o = object used to count the number of occurrences of each dice
    n =>               // for each dice n in a[]:
    [                  //   this is the lookup array for M-bitmasks:
      x =              //     x = o[n] = number of occurrences of the current dice
        o[n] = -~o[n], //     increment o[n] (we can't have M = 0, so this slot is not used)
      6,               //     M = 1 -> bitmask = 6
      ,                //     M = 2 -> bitmask = 0
      ,                //     M = 3 -> bitmask = 0
      21,              //     M = 4 -> bitmask = 21
      9,               //     M = 5 -> bitmask = 9
      8 ^ o[1]         //     M = 6 -> bitmask = 14 for six 1's, or 8 otherwise
    ][a =              //   take the entry corresponding to M (stored in a)
        x < a ? a : x] //   update a to max(a, x)
  )[5]                 // end of map(); keep the last value
  |                    // do a bitwise OR with the second bitmask
  [                    // this is the lookup array for F-bitmasks:
    ,                  //   F = 0 -> bitmask = 0
    1,                 //   F = 1 -> bitmask = 1
    4,                 //   F = 2 -> bitmask = 4
    5,                 //   F = 3 -> bitmask = 5
    o[1] & 2 | 8,      //   F = 4 -> bitmask = 10 if we also have two 1's, 8 otherwise
    2,                 //   F = 5 -> bitmask = 2
    4                  //   F = 6 -> bitmask = 4
  ][o[4]]              // take the entry corresponding to F (the number of 4's)

5

R,100字节

将分数编码为一堆索引条件句。比我的第一个严格的正则表达式方法简单。

编辑固定的错误,现在排名所有卷。

function(d,s=sum(d<2))min(2[s>5],c(11,10,8,6-6*!s-2,4,1)[sum(d==4)],c(7,12,12,9,5,3)[max(table(d))])

在线尝试!



2

Python 2中 148个  119字节

-27字节归功于ovs(1.使用.count允许使用a map; 2.删除0切片中的冗余; 3.使用a in而不是a max; 4.缩短(F==4)*O==2F==4>O==2[因为打高尔夫球到F>3>O>1])

C=map(input().count,range(1,7))
O,F=C[::3]
print[F>3>O>1,F>5,O>5,6in C,F>4,5in C,F>3,all(C),F>2,4in C,F>1,F,1].index(1)

在线尝试!


@ovs oh heh .count> _ <不错
Jonathan Allan

最后一个建议:d仅需一个建议,它作为一个完整的程序就更短了
ovs

Python 3版本:131字节
Adirio

@ovs-感谢您打高尔夫球。保存另两个启动。
乔纳森·艾伦,

必须爱python条件链接!此外,规格现在不会跳过数字10
Quintec

1

Pyth,60个字节

eS[@[ZhZ2 4*6hq2hJuXtHG1Qm0Q8hT)@J3*5hSJ*Tq6hJ*<3KeSJ@j937TK

映射到反向排名,0-12。在此处在线尝试,或一次验证所有测试用例此处

使用的完整映射如下:

12: 4 fours and 2 ones.
11: 6 fours.
10: 6 ones.
 9: 6 of any kind except fours and ones.
 8: 5 fours.
 7: 5 of any kind except for fours.
 6: 4 fours.
 5: Straight. (1-6)
 4: 3 fours.
 3: 4 of any kind except 4.
 2: 2 fours.
 1: 1 four.
 0: Nothing.

通过将骰子值映射到频率,然后计算几个规则的值,并取最大的值来工作。

Implicit: Q=eval(input()), Z=0, T=10

JuXtHG1Qm0Q   Input mapping
 u     Q      Reduce each element of the input, as H, ...
        m0Q   ...with initial value, G, as an array of 6 zeroes (map each roll to 0)
   tH           Decrement the dice roll
  X  G1         Add 1 to the frequency at that point
J             Store the result in J

@[ZhZ2 4*6hq2hJuXtHG1Qm0Q8hT)@J3   Rule 1 - Values for sets including 4
  Z                               *0
   hZ                             *1 (increment 0)
     2                            *2
       4                          *4
              JuXtHG1Qm0Q          Input mapping (as above)
             h                     First value of the above - i.e. number of 1's
           q2                      1 if the above is equal to 2, 0 otherwise
        *6h                       *Increment and multiply by 6
                                   Maps to 12 if there are 2 1's, 6 otherwise
                         8        *8
                          hT      *11 (increment 10)
 [                          )      Wrap the 7 starred results in an array
                             @J3   Get the 4th value of the input mapping - i.e. number of 4's
@                                  Get the value at that position in the array

*5hSJ   Rule 2 - Straight
  hSJ   Smallest frequency in input mapping (first, sort, J)
        For a straight, smallest value will be 1, 0 otherwise
*5      Multiply by 5

*Tq6hJ   Rule 3 - 6 1's
    hJ   Frequency of 1's (first value from input mapping)
  q6     1 if the above == 6, 0 otherwise
*T       Multiply by 10

*<3KeSJ@j937TK   Rule 4 - 4,5,6 of a kind, other than 4's
   KeSJ          Get the max frequency from input mapping, store in K
        j937T    [9,3,7]
       @     K   Get the element at K'th position in the above (modular indexing)
 <3K             1 if 3<K, 0 otherwise
*                Multiply the previous 2 results

eS[   Wrapping it all up!
  [   Wrap all the above rules in an array
eS    Take the max value of the above, implicit print

1

视网膜137126字节

4
A
O`.
^11A+
0
1+$
2
^A+
1
(.)\1{5}
3
^.A+
4
.?(.)\1{4}.?
5
^..A+
6
12356A
7
.+AAA$
8
.*(.)\1{3}.*
9
.+AA$
10
.+A$
11
.{6}
12

-11个字节感谢@Neil

输出为0索引(0..12)。

在线尝试验证所有测试用例

说明:

将每4个替换为'A':

4
A

对所有输入数字进行排序(A在后面):

O`.

每隔两行用预期的输出替换输入:

Regex         Replacement  Explanation

^11A+         0            starts with "11", followed by any amount of A's
1+$           2            ends with any amount of 1s
^A+           1            starts with any amount of A's
(.)\1{5}      3            six of the same characters
^.A+          4            starts with any character, followed by any amount of A's
.?(.)\1{4}.?  5            five of the same characters,
                           with optionally a leading or trailing character
^..A+         6            starts with any two characters, followed by any amount of A's
12356A        7            literal "12356A" match
.+AAA$        8            any amount of leading characters, ending with three A's
.*(.)\1{3}.*  9            four of the same characters,
                           with optionally any amount of leading/trailing chars
.+AA$         10           any amount of leading characters, ending with two A's
.+A$          11           any amount of leading characters, ending with a A
.{6}          12           any six characters

1
非常聪明,但是我认为您可以再走一步,并4用超出范围的内容1-6进行替换,以使其自动分类到一个末端(不知道它对分类的末端是否有影响)。
尼尔

@Neil啊,那也很聪明!谢谢。
凯文·克鲁伊森

1

05AB1E57 55 字节

4¢4@U.M¢©5-Di14¹нk2αë>Di5X-ë>i9X3*-¹1¢2Ê*ë®i7ë¹4¢o;ï12α

@Neil的Charcoal答案的端口,因为我的初始方法已经是60字节,但还没有完成。不过,我目前的答案可能还有更多。

输入为数字列表。

在线尝试验证所有测试用例

说明:

4¢              # Count the amount of 4s in the (implicit) input-list
  4@            # Check if it's larger than or equal to 4
                # (results in 1 for truthy; 0 for falsey)
    U           # Pop and store that result in variable `X`
.M              # Push the most frequent number in the (implicit) input-list
  ¢             # Pop and push the count of that number in the (implicit) input-list
   ©            # Store it in the register (without popping)
5-Di            # If the maximum count - 5 is exactly 1 (so the maximum count is 6):
    14          #  Push 14
      ¹н        #  Push the first digit of the input-list
        k       #  Get its index in 14, resulting in -1, 0, or 1
         2α     #  Take the absolute difference with 2
                #  (This covers cases 1, 2, and 3)
ë>Di            # Else-if the maximum count - 5 + 1 is exactly 1 (so the maximum count is 5):
    5           #  Push 5
     X-         #  And subtract variable `X`
                #  (This covers cases 4 and 5)
ë>i             # Else-if the maximum count - 5 + 2 is exactly 1 (so the maximum count is 4):
   9            #  Push 9
    X3*         #  Multiply variable `X` by 3
       -        #  And subtract it from the 9
        ¹1¢     #  Count the amount of 1s in the input-list
           2Ê   #  Check if it's NOT equal to 2 (1 if truthy; 0 if falsey)
             *  #  Multiply it with the 9 or 6
                #  (This covers cases 0, 6, and 9)
ë®i             # Else-if the maximum count is 1:
   7            #  Push a 7
                #  (This covers case 7)
ë               # Else (maximum count is 2 or 3):
 ¹4¢            #  Count the amount of 4s in the input-list
    o           #  Take 2 to the power this count
              #  Halve and floor it
       12α      #  And take the absolute difference with 12
                #  (This covers cases 8, 10, 11, and 12)
                # (Output the top of the stack implicitly as result)

0

红宝石,100字节

->a{%w(^2.*4$ 6$ ^6 6 5$ 5 4$ ^1*$ 3$ 4 2$ 1$ .).index{|b|/#{b}/=~([1,*a,4].map{|c|a.count(c)}*'')}}

在线尝试!

这个怎么运作:

计算数组中每个数字的出现次数,前一个数字为1s,后一个数字为4s。

之后,尝试匹配不同的正则表达式模式。

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.