코드 골프 골프 점수 프로그램 일 수 있습니다.

금요일입니다 … 골프를 타러 가자! 골프 경기에서 홀에 대한 플레이어의 득점을 결정하는 코드를 작성하십시오. 코드는 함수 또는 전체 프로그램 일 수 있습니다. 장르에서 알 수 있듯이 가장 짧은 코드가 승리합니다.

입력 (파라미터 또는 표준 입력, 선택) :

  • 홀의 파를 나타내는 정수로 3에서 6 사이입니다.
  • 골퍼의 점수를 나타내는 정수로 1과 64 사이에 있습니다.

출력 (표준 출력 또는 리턴 인쇄, 후행 줄 바꿈이 허용되지만 필수는 아님) :

  • 점수가 1이면 “Hole in one”을 출력하십시오.
  • score == par-4 및 par> 5이면 “Condor”를 출력하십시오.
  • score == par-3 및 par> 4 인 경우 “Albatross”출력
  • score == par-2 및 par> 3이면 “Eagle”을 출력합니다
  • score == par-1 인 경우 “버디”출력
  • score == par 인 경우 “Par”출력
  • score == par + 1이면 “Bogey”출력
  • score == par + 2 인 경우 “Double Bogey”출력
  • score == par + 3이면 “Triple Bogey”를 출력합니다
  • 점수> par + 3 인 경우 “Haha you loser”

편집 가장 짧은 답변을 얻은 데니스에게 축하합니다!



답변

젤리 , 61 바이트

_«4ị“Ƙḷ“&SẆ@ẓ“&T¡UQ“½⁽Ð'÷ṿɼ“½Œż“¡œM“v⁵“¥⁻c“£Ḋ⁶»
瓵ḣ⁻×⁵ñBƑ»’?

온라인으로 사용해보십시오!

배경

이것은 Jelly의 정적 사전 압축을 사용합니다. 여기 에서 압축기를 찾을 수 있습니다 . 이 방법,

“Ƙḷ“&SẆ@ẓ“&T¡UQ“½⁽Ð'÷ṿɼ“½Œż“¡œM“v⁵“¥⁻c“£Ḋ⁶»

“Bogey“Double Bogey“Triple Bogey“Haha you loser“Condor“Albatross“Eagle“Birdie“Par”

만큼 잘

“µḣ⁻×⁵ñBƑ»

“Hole in one”

동일합니다.

작동 원리

_«4ị“Ƙḷ“&SẆ@ẓ“&T¡UQ“½⁽Ð'÷ṿɼ“½Œż“¡œM“v⁵“¥⁻c“£Ḋ⁶»  Helper link. Arguments: score, par

_                                                Subtract the par from the score.
 «4                                              Cap the difference at 4.
   ị                                             Index into the list at the right.
    “Ƙḷ“&SẆ@ẓ“&T¡UQ“½⁽Ð'÷ṿɼ“½Œż“¡œM“v⁵“¥⁻c“£Ḋ⁶»  Yield a list of strings.


瓵ḣ⁻×⁵ñBƑ»’?  Main link. Arguments: score, pair

            ?  If...
           ’   the decremented score if non-zero:
ç                Call the helper link on both input arguments.
 “µḣ⁻×⁵ñBƑ»      Else, return “Hole in one”.


답변

PHP 5.3+, 173 167 166 159 156 151 127 121 바이트

echo[Condor,Albatross,Eagle,Birdie,Par,$b=Bogey,"Double $b","Triple $b","Haha you loser"][min(4+$s-$p,8)]?:"Hole in one";

통지가없는 버전, 139137 바이트

echo$s-1?["Condor","Albatross","Eagle","Birdie","Par",$b="Bogey","Double $b","Triple $b","Haha you loser"][min(4+$s-$p,8)]:"Hole in one";

$s핵심 $p변수 와 ar 변수를 설정하십시오 echo.

분해도

echo [Condor,
      Albatross,
      Eagle,
      Birdie,
      Par,
      $b = Bogey,
      "Double $b",
      "Triple $b",
      "Haha you loser"][ min( 4+$s-$p,8 ) ]
  ?: "Hole in one";

편집
-6 : 배열을 저장하지 않고 필요한 경우 호출하기 만하면됩니다.
-1 : 삼항을 뒤집습니다.
-7 : 최저 $s-$p$s>1이다 -4는 그래서 max()이후, 필요하지 않습니다 4+$s-$p >= 0.
-3 : Array -> explode() 감사합니다 CoolestVeto!
-5 : Cheaty 문자열 리터럴 undefined constant plus $r[-1] -> false, 감사합니다 Ismael Miguel!
-24 : 에서 이동하는 explode()(A)에 기능 printf/ %s방향의 변화 이스마엘 미겔 일부 비틀기 더 덕분으로 설정.
-6 : Swerve , 다시 돌아온다 echo!


답변

05AB1E , 91 90 바이트

암호:

-5+U“¥Ê€†€µ“ª"0Bogey"ДCondor Albatross²è Birdie Par ÿ‹¶ÿ½¿ÿ”ð¡“Haha€î loser“X0¹1Qm*@0ð:ðÛ

설명:

1 부:

-5+                          # Computes Score - Par + 5
   U                         # Store in X
    “¥Ê€†€µ“ª                # Short for "Hole in one"
             "0Bogey"        # Push this string
                     Ð       # Triplicate

2 부:

”Condor Albatross²è Birdie Par ÿ‹¶ÿ½¿ÿ”ð¡

이것은 "Condor Albatross Eagle Birdie Par 0Bogey Double0Bogey Triple0Bogey"문자열 압축과 문자열 보간 을 사용 하는 것과 같습니다 . 그런 다음을 사용하여 공백으로 분할합니다 ð¡.

3 부 :

“Haha€î loser“                # Push "Haha you loser"
              X               # Push X
               0¹1Qm          # Compute 0 ^ (score == 1), this translates 1 to 0 and
                                everything else to 1.
                    *         # Multiply the top two items
                     @        # Get the string from that position
                      0ð:     # Replace zeros with spaces
                         ðÛ   # Trim off leading spaces

CP-1252 인코딩을 사용 하여 많은 버그를 발견했습니다 .

온라인으로 사용해보십시오!


답변

Vitsy, 131 바이트

D1-)["eno ni eloH"rZ;]r-5+D9/([X9]mZ
"rodnoC"
"ssortablA"
"elgaE"
"eidriB"
"raP"
"yegoB"
4m" elbuoD"
4m" elpirT"
"resol uoy ahaH"

설명:

D1-)["eno ni eloH"rZ;]r-5+D9/([X9]mZ
D1-)[                ]      If the second input is 1, do the bracketed stuff.
     "eno ni eloH"rZ;       Output "Hole in one" and quit.
r                           Reverse the stack.
 -                          Subtract the top two items.
  5+                        Add 5 to fix for negative values of score.
    D9/([  ]                If the result of that is greater than 8, do the stuff in brackets.
         X                  Remove the top item.
          9                 Push 9. This forces any items greater than 8 to be 9.
            m               Execute this number line.
             Z              Output everything in the stack.

이것은 점수가 파에 상대적인지 파악한 다음 다른 줄을 실행하고 다른 줄을 얻음으로써 작동합니다.

온라인으로 사용해보십시오!

상세 모드 (똥과 낄낄 거림) :

duplicate top item;
push 1;
subtract top two;
if (int) top is not 0;
begin recursive area;
toggle double quote;
push 14;
eval(stack);
capture stack as object with next;
 ;
eval(stack);
push input item;
 ;
push 14;
push length of stack;
capture stack as object with next;
push all ints between second to top and top;
toggle double quote;
reverse stack;
output stack as chars;
generic exit;
end recursive area;
reverse stack;
subtract top two;
push 5;
add top two;
duplicate top item;
push 9;
divide top two;
if (int) top is 0;
begin recursive area;
remove top;
push 9;
end recursive area;
goto top method;
output stack as chars;
:toggle double quote;
reverse stack;
capture stack as object with next;
push 13;
eval(stack);
capture stack as object with next;
push cosine of top;
toggle double quote;
:toggle double quote;
push inverse sine of top;
push inverse sine of top;
capture stack as object with next;
reverse stack;
push inverse tangent of top;
push 10;
push 11;
push length of stack;
push inverse cosine of top;
toggle double quote;
:toggle double quote;
push 14;
push length of stack;
g;
push 10;
push e;
toggle double quote;
:toggle double quote;
push 14;
push input item;
push 13;
reverse stack;
push input item;
B;
toggle double quote;
:toggle double quote;
reverse stack;
push 10;
push pi;
toggle double quote;
:toggle double quote;
push number of stacks;
push 14;
g;
capture stack as object with next;
B;
toggle double quote;
:push 4;
goto top method;
toggle double quote;
 ;
push 14;
push length of stack;
push 11;
flatten top two stacks;
capture stack as object with next;
duplicate top item;
toggle double quote;
:push 4;
goto top method;
toggle double quote;
 ;
push 14;
push length of stack;
push whether (int) top item is prime;
push input item;
reverse stack;
push tangent of top;
toggle double quote;
;
;
:toggle double quote;
reverse stack;
push 14;
push inverse sine of top;
capture stack as object with next;
push length of stack;
 ;
flatten top two stacks;
capture stack as object with next;
push number of stacks;
 ;
push 10;
factorize top item;
push 10;
push all ints between second to top and top;
toggle double quote;


답변

자바 스크립트 (ES6) 125 124 바이트

p=>s=>"Hole in one,Condor,Albatross,Eagle,Birdie,Par,Bogey,Double Bogey,Triple Bogey".split`,`[s-1&&s-p+5]||"Haha you loser"

예를 들어 변수에 할당하고 f=p=>s=>다음과 같이 호출하십시오 f(6)(2).

을 조합하여 단축 할 수 있습니다 "Bogey".


답변

LittleLua-160 바이트 (비경쟁)

r()P=I B="Bogey"r()Z={"Hole in one","Condor","Albatross","Eagle","Birdie","Par",B,"Double "..B,"Triple "..B,"Haha, you loser"}p(I=='1'a Z[1]or Z[I-P+6]or Z[10])

나는 내가 이것을 올바르게했다고 비교적 확신한다.

두 개의 정수, 파와 플레이어의 점수를받습니다.

이 도전에 사용한 Little Lua의 버전은이 챌린지가 게시 된 후에 업로드되었지만 나중에 편집되지 않았습니다. 이 도전을 단순화하기 위해 아무것도 추가되지 않았다는 것은 코드에서 비교적 분명합니다.

LittleLua 정보 :

Little Lua의 기본 제공 기능과 기능에 만족하면 정보 페이지와 함께 소스를 사용할 수 있습니다.

LittleLua V0.02


답변

Mouse-2002 , 223207 바이트

댓글을 삭제하면 도움이 될 것입니다 …

??s:p:s.1=["Hole in one"]s.p.4-=p.5>["Condor"]s.p.3-=p.4>["Albatross"]s.p.2-=p.3>["Eagle"]s.p.1-=["Birdie"]s.p.=["Par"]s.p.1+=["Bogey"]s.p.2+=["Double Bogey"]s.p.2+=["Double Bogey"]s.p.3+>["Haha you loser"]$

언 골프 드 :

? ? s: p:

s. 1 = [
  "Hole in one"
]

~ 1
s. p. 4 - = p. 5 > [
  "Condor"
]

~ 2
s. p. 3 - = p. 4 > [
  "Albatross"
]

~ 3
s. p. 2 - = p. 3 > [
  "Eagle"
]

~ 4
s. p. 1 - = [
  "Birdie"
]

~ 5
s. p. = [
  "Par"
]

~ 6
s. p. 1 + = [
  "Bogey"
]

~ 7
s. p. 2 + = [
  "Double Bogey"
]

~ 8
s. p. 2 + = [
  "Double Bogey"
]

s. p. 3 + > [
  "Haha you loser"
]


$