การให้คะแนนสนุ้กเกอร์


16

ฉันกำลังดูแชมป์โลกสนุกเกอร์และมันทำให้ฉันสงสัย ..

การให้คะแนนสนุ้กเกอร์

ในเกมสนุ๊กเกอร์มีกฎบางอย่างที่คุณต้องปฏิบัติตามเช่นกัน:

  • เมื่อมีลูกบอลสีแดงบนโต๊ะในช่วงตาคุณคุณจะต้องแทงลูกบอลสีแดงก่อน
  • หลังจากปลูกลูกบอลสีแดงแต่ละลูกคุณจะต้องแทงลูกบอลสี (ไม่ใช่สีแดง) (ลูกบอลสีกระถางจะถูกแทนที่ลงบนโต๊ะ)
  • หลังจากลูกบอลสีแดงทั้งหมดขึ้น (มี 15) คุณสามารถเลือกลูกบอลสีก่อนแล้วจึงเริ่มด้วยลูกบอลคะแนนต่ำสุดและทำตามวิธีของคุณจนถึงลูกบอลคะแนนสูงสุด (เหล่านี้จะไม่ถูกแทนที่)
  • ไม่ได้เติม ณ จุดใดก็ตามจะเป็นการปิดตาคุณ
  • คะแนนต่อบอล
    • ลูกบอลสีแดง: 1 จุด
    • ลูกบอลสีเหลือง: 2 คะแนน
    • ลูกบอลสีเขียว: 3 คะแนน
    • ลูกบอลสีน้ำตาล: 4 คะแนน
    • ลูกบอลสีน้ำเงิน: 5 คะแนน
    • ลูกบอลสีชมพู: 6 คะแนน
    • ลูกบอลสีดำ: 7 คะแนน

คำถาม

คุณเริ่มต้นด้วยโต๊ะที่ลูกบอลทุกลูกยังคงอยู่ - ลูกบอลสีแดง15ลูกและลูกบอลสีหนึ่งในแต่ละลูก - และได้รับคะแนนผู้เล่นในสนุ๊กเกอร์หลังจากรอบแรกของพวกเขาสิ่งที่เป็นไปได้ที่พวกเขาจะประสบความสำเร็จ คะแนน?

ข้อมูลที่ป้อนจะเป็นคะแนนตั้งแต่ 1 ถึง 147 คุณสามารถเลือกได้ว่าจะเป็นจำนวนเต็มหรือสตริง ผลลัพธ์ควรเป็นการรวมจำนวนครั้งที่แตกต่างกันที่คุณได้วางกระถางแต่ละลูก

กรณีทดสอบ:

Input: 4
Output: 
1r 1g
2r 1y
Input: 25
Output:
4r 3b
5r 2b 1br 1y
5r 2b 2g
...
9r 8y

กฎ:

  • คุณสามารถเลือกได้ว่าคุณจะส่งออกความเป็นไปได้ที่หารด้วยบรรทัดใหม่หรือตัวคั่นของการเรียงลำดับบางอย่าง (/ ,; | \ หรือแม้กระทั่งสิ่งที่ฉันขาดหายไป)

นี่คือ codegolf ดังนั้นรหัสที่สั้นที่สุดชนะ


ฉันสามารถส่งออกเป็นรายการของอาร์เรย์ได้หรือไม่
Leun Nun

1
เกี่ยวกับการส่งออกอาเรย์: จำนวนลูกที่เรียงตามคะแนนไม่ชัดเจนดังนั้นอาจ"5r 3b 2g"จะเป็นผลลัพธ์[5,0,2,0,3,0,0](ตราบใดที่มันสอดคล้องกัน)?
Jonathan Allan

2
คุณใช้bสำหรับสีน้ำตาลและblสีน้ำเงิน ดังนั้นbkสำหรับสีดำ เราสามารถใช้n, eและk(ตัวอักษรที่ผ่านมา) ทั้งสาม? วิธีdlerunaการระบุแปดสีทั้งหมด (ตัวอักษรที่สามของแต่ละ)?
Jonathan Allan

1
@Shaggy หากคุณใช้การระบุสีเช่น dleruna หรืออีกอันหนึ่งไม่ใช่ หากคุณใช้อาเรย์เช่น [5 0 0 4 1 0 0] ก็ควรจะเรียงจากต่ำไปสูง
Michthan

1
เพื่อจุดประสงค์ในการสาธิตนี่เป็นตัวอย่าง (ที่น่าทึ่ง) ของการหยุดพัก 147 ครั้งโดย Ronnie "The Rocket" O 'Sullivan
Arnauld

คำตอบ:


6

วุ้น 66 ไบต์

L⁼30µÐfµ7Ḋ;\¤;€Ṣ€µ€;/
ċ1<⁴µÐfµ;Ç
7Ḋœċ⁴Ḷ¤;/L€;$€;@þ2B¤;/ḟ€0ÇS⁼¥Ðf⁸G

ตอนนี้ TIO ช้าเกินไปแล้ว!
... ดังนั้นนี่คือการวางวิธี 2636 เพื่อสร้าง100ออฟไลน์ที่ถูกต้อง
... และนี่คือรุ่นที่จะทำงานที่นั่นด้วยSIX reds (การหยุดพักสูงสุด = 75)

พิมพ์ตารางตัวเลขแต่ละบรรทัดเป็นช่องว่างคั่นรายการของค่าบอล (เช่นสามสีแดงและสีเขียวสองเส้นจะอ่านบนเส้น1 1 1 3 3)


สำหรับรุ่นที่มีการจัดกลุ่มค่าที่พิมพ์บรรทัดการนับพร้อมกับชื่อเต็มของลูกบอลที่ 102 ไบต์:

ŒrÑ€
Ṫ;ị“¡^³ṗ⁼¬wḌ⁼ø÷OẏK¦ẆP»Ḳ¤$K
L⁼30µÐfµ7Ḋ;\¤;€Ṣ€µ€;/
ċ1<⁴µÐfµ;Ç
7Ḋœċ⁴Ḷ¤;/L€;$€;@þ2B¤;/ḟ€0ÇS⁼¥Ðf⁸Ñ€K€Y

อย่างไร?

L⁼30µÐfµ7Ḋ;\¤;€Ṣ€µ€;/ - Link 1, create post-red-ball games: list of all pre-yellow-ball-games
    µÐf               - filter keep if:
L⁼30                  -   length equals 30 (games that get on to the yellow)
       µ         µ€   - for €ach sequence leading to the yellow:
            ¤         -   nilad followed by link(s) as a nilad:
        7Ḋ            -     7 dequeued  = [2,3,4,5,6,7]
          ;\          -     ;\ cumulative reduce with concatenation  = [[2],[2,3],[2,3,4],...]
             ;€       - concatenate the sequence with €ach of those
               Ṣ€     - sort each one
                   ;/ - reduce with concatenation (flatten by one)

ċ1<⁴µÐfµ;Ç - Link 2, filter bogus entries created and append post-yellow-ball games: list of pre-yellow-ball games (along with the bogus ones with 16 reds potted)
    µÐf    - filter keep if:
ċ1         -   count ones
   ⁴       -   literal 16
  <        -   less than?
       µ   - monadic chain separation
         Ç - call the last link (1) as a monad
        ;  - concatenate

7Ḋœċ⁴Ḷ¤;/L€;$€;@þ2B¤;/ḟ€0ÇS⁼¥Ðf⁸G - Main link: score
7Ḋ                                - 7 dequeued = [2,3,4,5,6,7]
      ¤                           - nilad followed by link(s) as a nilad:
     ⁴                            -   literal 16
    Ḷ                             -   lowered range = [0,1,2,...,15]
  œċ                              - combinations with replacement (every possible colour-ball selection that goes with the red pots)
       ;/                         - reduce with concatenation (flatten by one)
            $€                    - last two links as a monad for €ach:
         L€                       -   length of €ach (number of coloured balls potted)
           ;                      -   concatenate
                   ¤              - nilad followed by link(s) as a nilad:
                 2B               -   2 in binary = [1,0]
                þ                 - outer product with:
              ;@                  -   concatenation with reversed @rguments
                    ;/            - reduce with concatenation (flatten by one)
                      ḟ€0         - filter discard zeros from €ach
                         Ç        - call the last link (2) as a monad
                             Ðf   - filter keep:
                            ¥  ⁸  -   last two links as a dyad, with score on the right
                          S⁼      -     sum(ball values) is equal to score?
                                G - format as a grid
                                  - implicit print

มันทำงานได้ดีสำหรับทุกกรณีที่ฉันได้ลอง ในบางกรณีรหัสสุดท้ายจะให้ศูนย์นำหน้า
Michthan

อ่าใช่พวกเขาควรถูกกรองออก ... แก้ไข
Jonathan Allan

ผลลัพธ์ของคุณสำหรับ 53 หนึ่งนั้นไม่น่าสงสัยอย่างที่ฉันพูดไว้ก่อนหน้านี้ แต่ฉันยังคงสงสัยว่ามันสามารถอ่านได้สำหรับทุกคน ..
Michthan

มันเป็นวิธีที่ดีกว่ามากในตาราง หากไม่มีคำตอบสั้น ๆ ในอีกไม่กี่วันข้างหน้าฉันจะยอมรับคำตอบของคุณ!
Michthan

อืมมม ฉันได้รับการรวมกันในศตวรรษที่ 2636 ดังนั้นคุณหรือฉันผิด ...
Arnauld

4

JavaScript (ES7), 188 180 178 ไบต์

ส่งคืนอาร์เรย์ของอาร์เรย์ (เรียงลำดับจากสีแดงเป็นสีดำ)

n=>[...Array(17**6)].map((_,x)=>[2,3,4,5,6,p=7].map(v=>(k=a[++j]=x%17|0,x/=17,t+=k,p+=!!(y=y&&k),s-=k*v),y=s=n,a=[j=t=0])&&(s==15|s>=t)&s<16&s<t+2&t<9+p&&(a[0]=s,a)).filter(a=>a)

แสดงความคิดเห็น

หมายเหตุ : รุ่นนี้ไม่รวมการเพิ่มประสิทธิภาพล่าสุดในp(ตอนนี้เริ่มต้นที่ 7) ซึ่งทำให้ตรรกะยากต่อการเข้าใจ

n =>                              // given a target score n:
  [...Array(17**6)].map((_, x) => // for each x in [0 .. 17^6 - 1]:
    [2, 3, 4, 5, 6, 7].map(v =>   //   for each v in [2 .. 7] (yellow to black):
      ( k = a[++j] = x % 17 | 0,  //     k = a[j] = number of colored balls of value v
        x /= 17,                  //     update x to extract the next value
        t += k,                   //     update t = total number of colored balls
        p += !!(                  //     update p = number of consecutive colors that were
          y = y && k              //     potted at least once, using y = flag that is zeroed
        ),                        //     as soon as a color is not potted at all
        s -= k * v ),             //     subtract k * v from the current score s
      y = s = n,                  //     initialize y and s
      a = [j = t = p = 0]         //     initialize a, j (pointer in a), t and p
    )                             //   at this point, s is the alleged number of red balls
    &&                            //   this combination is valid if we have:
      (s == 15 | s >= t) &        //     - 15 red balls or more red balls than colored ones
      s < 16 &                    //     - no more than 15 red balls
      s < t + 2 &                 //     - at most one more red ball than colored ones
      t < 16 + p                  //     - no more than 15 + p colored balls
    &&                            //   if valid:
      (a[0] = s, a)               //     update the combination with red balls and return it
  ).filter(a => a)                // end of outer map(): filter out invalid entries

ตัวอย่างผลลัพธ์

ด้านล่างคือผลลัพธ์สำหรับ n = 140:

//  R   Y  G  Br Bl P  Bk 
[ [ 15, 1, 1, 1, 1, 8, 9  ],
  [ 15, 1, 1, 1, 2, 6, 10 ],
  [ 15, 1, 1, 1, 3, 4, 11 ],
  [ 15, 1, 1, 2, 1, 5, 11 ],
  [ 15, 1, 1, 1, 4, 2, 12 ],
  [ 15, 1, 1, 2, 2, 3, 12 ],
  [ 15, 1, 2, 1, 1, 4, 12 ],
  [ 15, 1, 1, 2, 3, 1, 13 ],
  [ 15, 1, 1, 3, 1, 2, 13 ],
  [ 15, 1, 2, 1, 2, 2, 13 ],
  [ 15, 2, 1, 1, 1, 3, 13 ],
  [ 15, 1, 2, 2, 1, 1, 14 ],
  [ 15, 2, 1, 1, 2, 1, 14 ],
  [ 15, 1, 1, 1, 1, 1, 15 ] ]

การสาธิต

นี่ช้าเกินไปสำหรับตัวอย่าง คุณสามารถลองที่นี่แทน (คุณอาจได้รับหนึ่งหรือสองแจ้งเตือนสคริปต์ไม่ตอบสนองแต่ในที่สุดก็ควรจะเสร็จสมบูรณ์)

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