Tennis task Algorithm

hello house, can someone help me with the algorithm or solution to the following task using JavaScript function:
You are hosting a tennis tournament. P players, who will take part in the first round of this tournament,
are already registered and you have reserved C tennis courts for the matches. Exactly two players play in each
game and only one game can be played on each court at any given time. You want to host the maximum possible number
of games starting at the same time (in order to finish the first round quickly).

How many games can be hosted in parallel simultaneously?

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://learn.freecodecamp.org.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

thanks for the response, I am just a beginner in programming, and I only want an algorithm that literally explain the task not any line of code

so you want the psuedocode?

yes…that is all I wanted…from there I will come up with a function and if I get stuck, I will check back

have you tried coming up with the pseudocode yourself?

1 Like

yes, buh is not worth sharing…is scary…:upside_down_face:

try it yourself first

It’s all scary isn’t it!

When you share your pseudocode, we can see whre your current thinking and knowledge is. Without knowing that we are not teaching, just giving an answer.

Do your best without worrying if it is good or bad, and we will help you move forward to come up with the right answer.

You don’t even have to write pseudocode, just talk (write) through your line of thinking

1 Like

thanks…
Now, I believe number of Registered Player which is P, will always be an even number,
let number of possible games = P/2;

if reserved number of tennis court (N) which is fixed (Constant) is odd, then return absolute(N- P/2)
else
return 2(P-N) as the number of matches that can occur at parallel simultaneously;

where did N came from? in your explanation there were only C and P

it was a mistake…i wanted to refer to C instead of N.
am sorry

so, if you have 22 players and 5 camps, how many games would it be?

if you have 10 camps and 18 players, how many games would it be?

If 22 players and 5camps, then it should return 5games at parallel simultaneously… i.e 5 games will be played at the same time on those 5 different court or camps

Please if you can just explain things to me kindly do… Or if you have a link where I can study mathematics and algorithm very well which will help my coding career kindly share it with me… I really want to learn.

so you know what it should return in one case
and in the other?

so you have the pseudocode! you just need to put variables in the steps you do instead of the actual numbers!

for mathematics I suggest Khan Academy

but for algorithms, it is practice that will make you get better

Back tracking to what @ieahleen is saying, practice is the only way to get better at algorithms, even if you were to find a code solution to the problem and studying it, it won’t help you much without actually implementing it yourself and understanding how each little task is done.

Since you’re a beginner I would recommend maybe tackling the problem one tiny step at a time, since you already have the pseudo code there, and if you feel at a lost still, like not knowing how to translate that into code. I would say to review more up on JavaScript on the curriculum, and getting familiar with its available methods, and to tackle simpler algorithms, so you can have a better understanding on how to piece this bigger problem together.

This is correct. Can you answer the other question posted? Ie what if there are 10 camps and 18 players, how many games would there be? Hint: THere can’t be 10 games.

Now ask yourself how are the two cases different and why do they ahve different answers.

you are doing things correctly so far, have confidence in your abilities.

1 Like

Am grateful sir, sincerely you are opening my eye with the way you sound and the first word “This is correct”.
Sincerely I have been thinking about huge and complex mathematics and am getting discouraged believing that they are lying when I read that you “you don’t need to be mathematics guru before becoming a programmer”.
In response to your post, am able to come up with this:
If P/2 is greater than C, return C;
else if P/2 is less than C, return P/2;
else return P/2;
Thank you so much…I wish you could be of more help to me in coding career…
Thanks for taken it softly with me.
Thanks.