22
1
It's Friday... so let's go golfing! Write code that determines the player's scoring on a hole in a game of golf. The code can be either a function or entire program. As the genre suggests, shortest code wins.
Input (parameters or stdin, your choice):
- An integer representing the hole's par, guaranteed to be between 3 and 6
- An integer representing the golfer's score, guaranteed to be between 1 and 64
Output (print to stdout or return, trailing newline allowed but not required, your choice):
- if score is 1, output "Hole in one"
- if score == par - 4 and par > 5, output "Condor"
- if score == par - 3 and par > 4, output "Albatross"
- if score == par - 2 and par > 3, output "Eagle"
- if score == par - 1, output "Birdie"
- if score == par, output "Par"
- if score == par + 1, output "Bogey"
- if score == par + 2, output "Double Bogey"
- if score == par + 3, output "Triple Bogey"
- if score > par + 3, output "Haha you loser"
EDIT Congrats to Dennis on having the shortest answer!
34I always wondered what was after triple bogey. – ThisSuitIsBlackNot – 2016-03-04T19:27:12.220
3Incidentally the largest par is 7 not 6. – Joshua – 2016-03-04T20:57:56.143
4@Joshua I was temporarily confused about why you commented instead of edited your own post. Then it hit me. :P – Rɪᴋᴇʀ – 2016-03-04T21:25:17.307
@RikerW the two Josh's names are as close as their reputation :D – cat – 2016-03-04T21:55:52.480
What if score == 1 and par == 2 ? – None – 2016-03-04T22:15:15.410
@RickyDemer: Par is not allowed to be less than 3; however if it were you would you would output "Hole in one". – Joshua – 2016-03-04T22:16:17.303
What is the point of the "and par > X" clauses? Surely the "Hole in one" criteria being checked first would make that step unnecessary? – Darrel Hoffman – 2016-03-04T22:38:27.670
2Can the input be in any order? – Doorknob – 2016-03-05T01:26:54.143
@Doorknob input can be in any order. – Josh – 2016-03-07T13:20:26.130