中秋節のギャンブルゲーム


11

明日は中秋節であり、その休日の精神で、私たち(ia門の人々)が休日中にプレイするギャンブルゲームを紹介します!

ルール

ゲームは6つの6面のサイコロでプレイされます。数字の異なる組み合わせは、4と1に特に重点を置いて、異なるランクを持っています。あなたの仕事は、6個のサイコロを振ってハンドをランク​​付けするプログラム/関数を書くことです。ランクは次のとおりです(ルールを少し変更/簡略化しました)。

ランク

中国人だけがこの挑戦をすることができると思います!わかりました、ここにいくつかの英語の説明があります。

  • 0:4つの4と2つの4。
  • 1:四つんばい。
  • 2:6個。
  • 3:4と1を除くあらゆる種類の6。
  • 4:5 4。
  • 5:4以外のあらゆる種類の5。
  • 6:4 4。
  • 7:ストレート。(1-6)
  • 8:3 4。
  • 9:4を除くあらゆる種類の4。
  • 10:2 4。
  • 11:1 4。
  • 12:なし。

入力

6個の数字、6個の数字の配列、または1〜6の6個のサイコロの値を表す6個の数字の文字列

出力

各ランクが1つの出力で示される限り、プログラム/関数はランクを示すために何かを返したり出力したりできます。例 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を出力すると言います
浅本シエル

@Shaggy質問で述べたように、出力は必ずしもラベル番号に対応する必要はありません。画像のスキップされた数とランダムなギャップは、ルールを少し単純化するためです-この伝統には明確なルールはありません。これは私の解釈です。
クインテック

あるべきではない[1,2,3,5,6,6]->13??
J.Doe

@ J.Doe examples / test-casesは、値の代わりに結果としてインデックスを使用します。値とは異なり、10はスキップされません。
ケビンCruijssen

回答:


2

、55バイト

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

オンラインでお試しください!リンクは、コードの詳細バージョンです。10はスキップしません。説明:

≡⌈Eθ№θι

任意の桁の最高頻度を計算します。

⁶I⁻²⌕14§θχ

6の種類がある場合、文字列内の数字の位置を142から減算します。これにより、6 4の場合は1、6 1の場合は2、その他の6の場合は3になります。

⁵I⁻⁵⁼⁵№θ4

種類が5の場合、4が5つない限り結果は5になり、その場合は1が減算されます。

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

種類が4の場合、4が4であれば、結果は0になり、そうでない場合は9になります。

¹7

すべての数字が異なる場合、結果は7です。

I⁻¹²⌊⊘X²№θ4

それ以外の場合、結果は12-(4 >>(3-#of 4s))です。


...残念ながら、多くの人々が見た:)私はやるの何という、最短の答えを受け入れるためのベストプラクティスのようですし、あなたの答えをupvoted
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

どうやって?

方法

出力は、次の間でビット単位のORを実行することにより計算されます。

  • F
  • M

例外:

  • F=44b4a
  • M=66b6a

テーブル

FM

F01234a4b56MOR014581024166767141466200145810243001458102442121212121293123215999131391111136a889121381010126b141415141514141414

M3M3MF=3

M=1F=1

6 OR 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

パイソン2 148の  119バイト

-27 OVSのおかげバイト(1.使用.count可能map、冗長の2除去に使用する0スライス内、3の使用inではなくmax、短縮4 (F==4)*O==2F==4>O==2【にgolfed以降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> _ <nice
ジョナサンアラン

最後の提案:d必要なものだけなので、これは完全なプログラムとして短くなります。
ovs


@ovs-すべてのゴルフに感謝します。ブートするために別の2つを保存しました。
ジョナサンアラン

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

@Neilのおかげで-11バイト。

出力は0から始まります(0..12)。

オンラインそれを試してみたり、すべてのテストケースを確認してください

説明:

4個ごとに「A」に置き換えます。

4
A

すべての入力桁を並べ替えます(Aは後ろになります)。

O`.

2行おきに、入力を期待される出力に置き換えます。

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自動的に一方の端に並べ替えることができると思います(並べ替えの終わりに違いがあるかどうかはわかりません)。
ニール

@ニールああ、それも賢いです!ありがとう。
ケビンクルーイッセン

1

05AB1E57 55 バイト

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

@Neilのチャコール回答のポート。私の最初のアプローチはすでに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)}*'')}}

オンラインでお試しください!

使い方:

配列内のすべての数字の出現回数をカウントし、1の数字を追加し、4の数字を追加します。

その後、異なる正規表現パターンと一致するようにしてください。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.