Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Notifications
Mark all as read
Challenges

Golf golf challenge

+6
−0

The task is to create a program which displays a golf score as text. It takes 2 numbers as input, separated by space or new line:

  • The first number is the par of the specific hole.
  • The second number is the score that the player got.

The program should print the textual golf term for the result, given the par. Trailing spaces or line feed are allowed.

Par can be a value between 3 to 5 and is the score that the average golf player is expected to get at that hole for their result to be considered fine. A score lower than par is considered good, a score above par is considered bad.

  • A score of 1 is always called "Hole in one".
  • A score of -3 below par is called "Albatross".
  • A score of -2 below par is called "Eagle".
  • A score of -1 below par is called "Birdie".
  • A score of +1 above par is called "Bogey".
  • A score of +2 above par is called "Double bogey".
  • A score of +3 above par is called "Triple bogey".

Scores higher than +3 above par need not be supported by this program. Thus the score will always be a number between 1 and 5+3=8.

Examples of input and output:

4 4
Par

4 3
Birdie

4 5
Bogey

4 2
Eagle

5 2 
Albatross

3 1
Hole in one

4 1
Hole in one

3 6
Triple bogey

5 8
Triple bogey

4 6
Double bogey

This is (code) golf, shortest source per language wins.

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Casing (2 comments)

5 answers

+4
−0

Ruby, 110 106 bytes

Fixed capitalization and refactored for -4.

->p,s{d=s-p
s<2&&"Hole in one"||%w[Albatross Eagle Birdie Par Bogey Double Triple][d+3]+(d>1?" bogey":"")}

Attempt This Online!

Why does this post require moderator attention?
You might want to add some details to your flag.

2 comment threads

102 bytes (1 comment)
Incorrect capitalisation (2 comments)
+4
−0

C (gcc), 133 131 bytes

f(p,s){char*t="Hole in one\0Albatross\0Eagle\0Birdie\0Par\0Bogey\0Double bogey\0Triple bogey";for(--s?s+=5-p:0;s-=!*t++;);puts(t);}

Saved two bytes thanks to m90 in the comments.

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

3 comment threads

126 bytes by indexing into an array (1 comment)
Improvement: `for(--s?s+=5-p:0;s-=!*t++;);` (2 comments)
Swapping char* for int* (2 comments)
+1
−0

Python 3, 108 bytes

lambda p,s:"Hole in one:Albatross:Eagle:Birdie:Par:Bogey:Double bogey:Triple bogey".split(':')[s-1and s-p+4]

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+0
−0

Python 3, 108 bytes

lambda p,s:s<2and"Hole in one"or"Par:Bogey:Double bogey:Triple bogey:Albatross:Eagle:Birdie".split(':')[s-p]

Try it online!

Very similar to my other solution, but handles the "Hole in one" case independently and uses wrap-around indexing for the other cases

Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

General comments (1 comment)
+0
−0

Ruby, 100 96 bytes

According to the rules, trailing white spaces and line feed are allowed and my program uses that:

->p,s{"Par
Bogey
Double bogey
Triple bogey
Hole in one
Albatross
Eagle
Birdie".lines[s<2?4:s-p]}

Try this online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!

Like what we're doing? Support us! Donate