I want to create a simple program in C/C++, as an exercise and for fun, that can say if an number entered by the user (a number between 0 and 250) can be a rugby score and to display all the possible combinations of points.
For those that do not know, in rugby you are awarded 5 points if you score a try, 2 points for a conversion (a conversion always follows a try) and 3 points for a goal kick (through a penalty kick or drop goal). So, for example, 5, 6, 7, 8 and 10 are valid scores, but 4 and 9 are not valid. Probably higher scores are all valid, so the most interesting part would be to display all possible combinations.
The algorithm I thought of using:
1) check if the score can be obtained only by tries or goal kicks (i.e. see if the number is divisible by 5 or 3).
2)
a) for 1 to n tries
b) in each try, for 0 to n conversions
check how many goal kicks are necessary to obtain the score (if it is possible)
Do you think it is a good algorithm? Can it be done in any other way?
If I will manage to create this I will share the program + the source code, if anyone is interested, of course.
Thanks,
bgd77