![]() This code I gave is still far from nice, it can be optimised further. I was able to get the runtime of the program from 452.8s to 3.2s t_iterator = 0 With changing as little as possible and taking into account that as Taylor said all of the sequences are increasing. for _, terms in enumerate(hexagonal):Įlif terms in triangle and terms in pentagonal: You have one million elements in every number group, every iteration of the for loop you are comparing one value to 2 million other values, when most of them can not be true. ![]() The main reason why your code is so slow is because your for loop in main spends most of the time checking for things that are logically impossible to be true. ![]() Check out the Project Euler discussion thread which you gain access to after solving the problem, and if you can distill out questions from that then ask them on our sister site. There are more sophisticated mathematical improvements, but this isn't the place. \textrm$$Ĭan you spot a major simplification which you can make to the search? Let us compare the runtime behavior of NumPy with normal Python lists. Triangle, pentagonal, and hexagonal numbers are generated by the bag-of-words approach is when we apply it to finding similar posts without. As a self-teaching Python beginner for almost 4 months, I have mostly been doing online challenges including Project Euler problems.
0 Comments
Leave a Reply. |