スヌーカーの得点


16

世界スヌーカー選手権を見ていましたが、不思議に思いました。

スヌーカーの得点

スヌーカーのゲームには、守らなければならない特定のルールがあります:

  • テーブルに赤いボールがある場合、あなたのターン中に最初に赤いボールをポットしなければなりません
  • それぞれの赤いボールをポッティングした後、色付きの(赤ではない)ボールをポッティングする必要があります(ポッティングされた色付きのボールはテーブルに置き換わります)
  • すべての赤いボールが上がった後(15個あります)、最初に色の付いたボールを選択してから、最も低いスコアのボールから始めて、最も高いスコアのボールまで進めます(これらは交換されません)。
  • ポッティングをしないと、ターンが終了します。
  • ボールあたりのポイント
    • 赤いボール:1ポイント
    • 黄色のボール:2ポイント
    • 緑色のボール:3ポイント
    • 茶色のボール:4ポイント
    • 青いボール:5ポイント
    • ピンクボール:6ポイント
    • ブラックボール:7ポイント

質問

すべてのボールがまだ残っているテーブル(15個の赤と他の各色のボールの1つ)から開始し、最初のターン後にスヌーカーのプレーヤーのスコアが与えられます。スコア?

入力は1〜147のスコアです。整数か文字列かを選択できます。出力は、各ボールをポットした回数の異なる組み合わせである必要があります。

テストケース:

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

ルール:

  • 可能性を新しい行で分割するか、ある種のセパレーター(/ ,; | \または私が見逃している他のセパレーター)で出力するかを選択できます。

これはcodegolfなので、最短のコードが優先されます。


配列のリストとして出力できますか?
リーキー修道女

1
配列の出力について:スコア順に並べられたボールの数は明確であるため"5r 3b 2g"[5,0,2,0,3,0,0](これが一貫している限り)出力される可能性がありますか?
ジョナサンアラン

2
b茶色とbl青に使用します。bk黒のため?これら3つにneおよびk(最後の文字)を使用できますか?dleruna8色すべて(各3文字目)を識別する方法は?
ジョナサンアラン

1
@Shaggy、ドレルナまたは他の色のような色の表示を使用する場合、いいえ。[5 0 0 4 1 0 0]のような配列を使用する場合は、低から高にソートする必要があります。
ミクサン

1
説明のためだけに、ロニー「ザ・ロケット」オ・サリバンによる147のブレイクの(驚くべき)例があります。
アーナルド

回答:


6

ゼリー、66 バイト

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

まあ、今はTIOには遅すぎます!
...ので、ここでは正確に作るために2636通りのペーストである100はオフラインを生産。
...そしてここに、6つの赤だけで実行されるバージョンがあります(最大ブレーク= 75)。

各行がスペースで区切られたボール値のリストである数値のグリッドを印刷します(たとえば、3つの赤と2つの緑が1行に表示されます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

私が試したすべてのケースでうまく機能します。場合によってのみ、最後のコードが先行ゼロを提供します。
ミクサン

ああ、それらは除外されるべきでした...修正されました。
ジョナサンアラン


グリッドの方がはるかに優れています。数日以内に短い回答がなければ、私はあなたの答えを受け入れます!
ミクサン

うーん。2636世紀の休憩の組み合わせを取得します。だから、どちらかあなたや私が間違っている...
アルノー

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 ] ]

デモ

これはスニペットには遅すぎます。代わりにここで試すことができます。(1つまたは2つの応答しないスクリプトアラートが表示される場合がありますが、最終的には完了するはずです。)

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