4
I recently managed to solve an algorithmic problem by enumerating all possible conditions. However, I believe that through some mathematical artifice, it would be possible to solve the problem more simply.
The problem can be seen here: https://neps.academy/problem/5
A fugitive, a helicopter and a police officer are in different positions on a circular track, exactly as shown in the figure next to them, with sixteen positions numbered from 0 to 15 in anti-clockwise direction. The helicopter and the policeman are always stopped. The objective of the fugitive is to get to the helicopter without passing the policeman first, of course. He may decide to run clockwise, or counterclockwise. In this problem, given the positions of the helicopter, the policeman and the fugitive, and the direction in which the fugitive decides to run, his program must tell whether or not he will be able to escape! In the picture, if the fugitive decides to run clockwise, he manages to flee; if he decides to run anti-clockwise, he will be arrested before arriving in the helicopter!
Entree
The input consists of a line with four integers: H, P, F and D, representing, respectively, the positions of the helicopter, the police officer and the fugitive, and the direction in which the fugitive runs, 1 for time and 1 for counterclockwise.
Exit
Your program must print a line containing the character "S" if the fugitive manages to escape, or "N" otherwise
Restrictions
The integers H, P and F are distinct and are between 0 and 15 inclusive
The intention of this post is to discuss some easier way to solve the problem in question... Please do not need to share resolution code. Answering the question with the mentioned solution (enumerate all conditions) is also not worth :P
PS.: If this post is not suitable for the forum, I apologize and if necessary, I can remove it.
Good! That’s what I wasn’t able to formulate :) Thanks Anderson :D
– Jeanderson Candido