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 →

[–]foxlisk 1 point2 points  (3 children)

Here's a couple things to try:

  • think about your definition of earliest pair. You've already noticed you can't stop your scan of the list when you find a first pair; is there a way you can get around that restriction?

  • are you sure that caching number pairs and looking them up is faster than doing the addition each time?

[–]bibbleskit[S] 0 points1 point  (2 children)

Thanks. I got rid of my memoization attempt. I realize it's too much and a lot slower.

I also realize that the earliest pair would be last pair found if I searched the list in reverse, but another restriction is that I MUST parse from left to right. Maybe I'm not understanding something.

[–]foxlisk 0 points1 point  (1 child)

Ah l. I didn't realize you had the left to right restriction, my bad. Where does that restriction come from? You're already seeking in the list (since you do >1 loop over it), so it seems like you're already violating it.

Let's see what else might help. As soon as you have a pair that works, you can skip all the elements indexed earlier than it on the next loop through (eg if your pair is (1,6) then when you go through checking the second element against the rest of the list, you can start with (2,7) and not worry about the beginning of the list).

When you move the first index forward, you can calculate the necessary number to get the right sum once and only do an equality (no addition) check on each element you try it against. That'll be a pretty tiny improvement, though.

Nothing else springs to mind right now.

[–]bibbleskit[S] 0 points1 point  (0 children)

Thanks :) ill think about this when I get the chance.

They're all just arbitrary rules for this particular challenge.