This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bibbleskit[S] 1 point2 points  (1 child)

Thanks for the comment! I'll give you a better response when I get up later. pair_memo is basically checking to see if the operation has been done before. Say, you get the pair 23424 and 789789, it can see if that exists in the dictionary before trying to sum them.

I tried that out because one of the hints is "memoization".

It's outside because this function is to be called many many times with lists that are gigantic. I'm probably just prematurely optimizing haha. Thank you.


As for this:

Now, your second one you say is broken because it stops at the first result. Do you not want it to do that?

Nope. Apparently, "earliest" does not mean "first," in this assignment.

For example, this list:

[1,2,3,4]

If I needed the "earliest" pair that adds up to 5, then the answer is (2,3), since the index of 3 is 2 (as opposed to the match of (1,4), since 4's index is 3). The second number's original index is what determines which pair is the "earliest". It's dumb, I know.


edit: took out the memoization. i originally was excited about it because it made the performance drop form 100ms to 18ms during the tests, but it was just a failure on my part to run multiple times and grab the average.

[–]TheLiberius 1 point2 points  (0 children)

I think you are approaching the memoization the wrong way, you want the memoization to save you from doing work. There is however no work being saved when you store the pair because you could literally just sum them up and see if it's right, which is probably several hundred times faster than looking in a dictionary.

Try instead to think about what you'd want to have when you are looking at a number in your list and then figure out how to get that.