เกมการพนันในเทศกาลไหว้พระจันทร์


11

พรุ่งนี้เป็นเทศกาลกลางฤดูใบไม้ร่วงและด้วยจิตวิญญาณของวันหยุดฉันจะแนะนำเกมการพนันที่เรา (ผู้คนจากเซียะเหมิน ) เล่นในช่วงวันหยุด!

กฎระเบียบ

เกมนี้เล่นโดยใช้ลูกเต๋า 6 ลูก 6 ด้าน การรวมกันของตัวเลขต่างกันมีอันดับที่แตกต่างกันโดยเน้นเป็นพิเศษทั้งสี่และคน งานของคุณคือการเขียนโปรแกรม / ฟังก์ชั่นที่จะจัดอันดับมือให้ได้รับ 6 ลูกเต๋า นี่คืออันดับ (ฉันได้แก้ไข / ลดความซับซ้อนของกฎเล็กน้อย):

การจัดอันดับ

ฉันเดาว่ามีเพียงคนจีนเท่านั้นที่สามารถทำสิ่งนี้ได้! โอเคนี่เป็นคำอธิบายภาษาอังกฤษ

  • 0: 4 fours และ 2 คน
  • 1: 6 fours
  • 2: 6 รายการ
  • 3: 6 ของทุกชนิดยกเว้นสี่และคน
  • 4: 5 fours
  • 5: 5 ทุกชนิดยกเว้นสี่
  • 6: 4 fours
  • 7: ตรง (1-6)
  • 8: 3 fours
  • 9: 4 ทุกชนิดยกเว้น 4
  • 10: 2 fours
  • 11: 1 สี่
  • 12: ไม่มีอะไร

อินพุต

6 ตัวเลข, อาเรย์ของตัวเลข 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

ไม่ควรใช่[1,2,3,5,6,6]->13มั้ย
J.Doe

@ J.Doe ตัวอย่าง / ทดสอบกรณีใช้ดัชนีเป็นผลแทนค่า ไม่เหมือนกับค่าต่าง ๆ แต่10จะไม่ถูกข้าม
Kevin Cruijssen

คำตอบ:


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 ยกเว้นว่ามี 5 4s ซึ่งในกรณีนี้ 1 จะถูกลบออก

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

หากมี 4 ชนิดดังนั้นถ้ามี 4 4s ผลลัพธ์จะเป็น 6 เว้นแต่ว่าจะมี 2 1 วินาทีซึ่งในกรณีนี้ผลลัพธ์เป็น 0 มิฉะนั้นผลลัพธ์คือ 9

¹7

หากตัวเลขทั้งหมดแตกต่างกันผลลัพธ์จะเป็น 7

I⁻¹²⌊⊘X²№θ4

ผลที่ได้คือ 12 - (4 >> (3 - # จาก 4s))


ดูเหมือนจะเป็นการปฏิบัติที่ดีที่สุดที่จะยอมรับคำตอบที่สั้นที่สุดดังนั้นฉันจะทำอย่างไร :) น่าเสียดายที่มีคนไม่มากที่เห็นและตอบโต้คำตอบของคุณ ...
Quintec

@Quintec นั่นไม่ใช่ปัญหา ผู้คนควรที่จะถอนคำตอบขึ้นอยู่กับความเฉลียวฉลาดของอัลกอริทึมหรือปัจจัยอื่น ๆ ที่ทำให้พวกเขาชื่นชมคำตอบ
Neil

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
  • 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 ไบต์

เข้ารหัสคะแนนเป็นเงื่อนไขที่จัดทำดัชนีไว้ ง่ายกว่าวิธีการแบบ stringy-regex แรกของฉัน

แก้ไข - แก้ไขข้อผิดพลาดและตอนนี้อันดับม้วนทั้งหมด

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 bytes

-27 ไบต์ขอบคุณที่ OVS ของ ( 1. ใช้.countช่วยให้มีการmapที่จะใช้ 2. การกำจัดของซ้ำซ้อน0ในชิ้น 3. การใช้inมากกว่าmax4. สั้นลง(F==4)*O==2ไปF==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


@ovs - ขอบคุณสำหรับการเล่นกอล์ฟของคุณทั้งหมด บันทึกอีกสองรายการเพื่อบูต
Jonathan Allan

ต้องรักงูหลามแบบมีเงื่อนไข! นอกจากนี้สเป็คตอนนี้จะไม่ข้ามหมายเลข 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

เรติน่า , 137 126 ไบต์

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

@ Neil Ah นั่นก็ฉลาดเช่นกัน! ขอบคุณ
Kevin Cruijssen

1

05AB1E , 57 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)}*'')}}

ลองออนไลน์!

มันทำงานอย่างไร:

นับจำนวนที่เกิดขึ้นของทุกหมายเลขในอาร์เรย์, เติมหมายเลข 1s และผนวกหมายเลข 4s

หลังจากนั้นลองจับคู่กับรูปแบบ regex ที่แตกต่างกัน

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.