Finding a function from a set of ordered pairs