斯诺克计分


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,所以最短的代码获胜。


我可以输出为数组列表吗?
Leaky Nun

1
关于数组输出:按分数排序的球数是明确的,因此也许"5r 3b 2g"可以输出为[5,0,2,0,3,0,0](只要这是一致的)?
乔纳森·艾伦

2
您使用b棕色和bl蓝色;所以bk黑?我们可以为这三个使用nek(最后一个字母)吗?如何dleruna识别所有八种颜色(每种颜色的第三个字母)?
乔纳森·艾伦

1
@Shaggy,如果您使用诸如dereruna或其他颜色的指示,则不会。如果仅使用[5 0 0 4 1 0 0]这样的数组,则应将它们从低到高排序。
密森

1
仅出于说明目的,这是 Ronnie“ The Rocket” O'Sullivan突破147的一个令人惊讶的例子
Arnauld

Answers:


6

果冻,66 字节

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

好吧,对于TIO来说太慢了!
...因此是2636种方法的粘贴,可精确地使100种脱机生产。
... 是一个可以在其中运行的版本,只有六个红色(最大中断= 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 '17

嗯,是的,它们应该被过滤掉了。
乔纳森·艾伦

正如我之前所说,您的53的输出是明确的,但是我仍然怀疑它是否对所有人
都可

以网格方式要好得多。如果接下来几天没有更短的答案,我将接受您的答案!
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 ] ]

演示版

对于摘要来说,这太慢了。您可以在这里尝试。(您可能会收到一两个无响应的脚本警报,但最终应该会完成。)

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.