스누커 득점


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]있습니까?
Jonathan Allan

2
당신이 사용하는 b갈색과 bl청색; 그래서 bk검정을 위해? 우리가 사용할 수 n, e그리고 k(마지막 편지)는이 세 가지에 대해? 방법에 대한 dleruna여덟 개 색상 (각 3 글자)를 식별하기 위해?
Jonathan Allan

1
@Shaggy, dleruna 또는 다른 것과 같은 색상 표시를 사용하는 경우 아니요. [5 0 0 4 1 0 0]과 같은 배열을 사용하는 경우 낮은 순서에서 높은 순서로 정렬해야합니다.
Michthan

1
설명을 위해 Ronnie "The Rocket"O 'Sullivan이 147 번 나누는 예가 있습니다.
Arnauld

답변:


6

젤리 , 66 바이트

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

글쎄, 지금은 TIO에게는 너무 느립니다!
... 그래서 여기에 정확하게 만들 수있는 2,636 가지의 페이스트 (100)는 오프라인을 생산했다.
... 여기6 개의 빨간색으로 실행되는 버전이 있습니다 (최대 나누기 = 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

내가 시도한 모든 경우에 잘 작동합니다. 어떤 경우에만 마지막 코드는 선행 0을 제공합니다.
Michthan

아 맞다. 그들은 걸러 내야했다.
Jonathan Allan

이전에 말한 것처럼 53 하나에 대한 귀하의 결과는 분명하지만 모든 사람이 읽을 수 있는지 여전히 의심
스럽습니다

그리드 방식으로 훨씬 좋습니다. 며칠 내에 더 짧은 답변이 없으면 답변을 받겠습니다.
Michthan

흠. 나는 2636 세기 휴식 조합을 얻습니다. 그래서 당신 또는 내가 틀렸다 ...
Arnauld

4

자바 스크립트 (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.