linear time solution
added once function to save results, can be used in conjunction with fibonacci