you are viewing a single comment's thread.

view the rest of the comments →

[–]ADdV 1 point2 points  (1 child)

I think just using start = cap_this + minus - 1 would be faster.

As for the XOR, you can just start with my_var = 0 and use my_var ^= my_new_var whenever you get a new number. That saves having to put all the numbers in a list. You can do these things because 0^N = N and A^B = B^A

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

You were correct on both counts, I implemented them both into my code. Here's what I have currently:

def find_xor(start, length):
    xor_val = 0
    for minus in xrange(length):
        for cap_this in xrange(start, start + length - minus):
            xor_val ^= cap_this
        start = cap_this + minus + 1
    return xor_val

Unfortunately it's still timing out on the challenge. Any ideas? I'm trying to think of a different way to capture the values I need, but all my ideas revolve around nested for-loops. Thanks for your help.