Working solver of the exercise. Returns values, results unchecked