
Scott P. answered 05/27/21
Experienced, patient computer/computer science tutor
The actual answer will depend on what language you are using, but a very crude approach to this in Python would be something like the code below. Note that there are many ways to actually do this, some of which are a little hard to understand if you are a new programmer, so this is a "brute force" approach that should be fairly clear as far as the logic goes:
By the way, adding this for if you want a more advanced solution (very Python-specific):