PE 75 primitive Pythagorean triples

  • Thread starter Arman777
  • Start date
  • Tags
    Primitive
In summary: Second, we can use a faster function in python to find primitive triples called gcd(). It takes O(n*log(n)) time. Third, we can use a different algorithm called sieving. In summary, The question asks for primitive Pythagorean triples such that S=a+b+c<15×105. The first way is to find all the primitive triples and it takes 1.6 seconds in Python. The second way is to use a faster function called gcd(). It takes O(n*log(n)) time. The third way
  • #36
Vanadium 50 said:
Nonsense.

I mean arrays don't support (|) or (&) operations. Of course, array's can be used. But I have to transform these operations into the loops and that's not so good.

I'll do the same thing but using extra loops to create operations.

I can do the same with set's and only using 2 simple operation symbol. I don't see how using arrays would change the run-time, without changing the algorithm itself. (Also I remember that sets are faster then when searching numbers in it. In my previous question about prime numbers I guess)

I think the problem is in the algorithm itself.

I can try to create a method where at some steps I can reset the num_set_0 so that the length of set does not exceed ten thousand
 
Physics news on Phys.org
  • #37
OK, you're the boss. Your code runs in an hour, mine in milliseconds. What do I have to teach you. Good luck!
 
  • #38
I am not the boss. I just argued that just changing set to arrays would not make any difference without chaging the algorithm itself.

Because lists do not support -, &, | operations.

I created functions for these oprations and turn my code into the list version. At max_sum = 10 000, my code is 33 times faster then list version.

If there's a faster way then doing these logical operations on lists other then creating functions, maybe things could be different. But I don't know how to do that.
 

Similar threads

Replies
3
Views
2K
Replies
7
Views
2K
Replies
6
Views
1K
Replies
27
Views
4K
Replies
7
Views
2K
Replies
6
Views
1K
Replies
39
Views
3K
Back
Top