Want to try solving this problem? You can submit your code online if you log in or register.
Ishraq and Clement have lost their mango and need help finding it again! Ishraq and Clement are standing on a straight line. Their positions are denoted by a single integer specifying how far they are from the left-hand end of the line. The mango is also on the line, but its exact location is unknown. Both Ishraq and Clement know how far away from the mango they are, but they don't know what direction the mango is in. Given the location of Ishraq and Clement, and their respective distances to the mango, determine the location of the mango. It is guaranteed that there will always be a single possible location for the mango.
2 6 1 3
3
8 3 7 2
1
23 40 17 0
40
The first two numbers in the input respectively give Ishraq's and Clement's locations. So we can see that they are standing at locations 2 and 6. Now, we also know that Ishraq is distance 1 away from the mango, so the mango must either be at location 1 or 3. Clement knows that the mango is distance 3 away from him, so we can see that the mango has to be at location 3.
Here, Ishraq is standing at 8 and Clement is standing at 3. The mango has to be distance 7 from location 8 and distance 2 from location 3. Therefore the mango must be at location 1.
In this case, Clement is standing on the mango.
Privacy
statement
© Australian Mathematics Trust 2001-2021
Page generated: 1 December 2021, 11:39am AEDT