working for 3 numbers test as in problem description
first attempt to find the proper answer. probably very inefficient.