You have been approached by a leading toy manufacturer to automate the process of toy acceptance and rejection after production. The toys are measured by laser and you are given these measurements and the criteria to which they must comply.
For each toy, 3 measurements are given in millimeters (mm) followed by a tolerance, also in millimeters. Each measurement must be within the specified tolerance of every other measurement. A tolerance of 0 requires all measurements to be exactly the same. A first measurement of −1 signals the end of input.
All you need to do is output 0 if the toy is rejected and 1 if it has been accepted. A toy is rejected if at least one of the measurement pairs falls outside the specified tolerance zone.
5 9 20 2
5 5 5 0
-1
0
1