Project Euler 49 - Prime Permutations

Official link:

Thought Process

This was, in my opinion, one of the hardest problems in the first 50.

  1. I start by generating a list of primes between 1,000 and 10,000 using my prime generation function

  2. I initialise a list called super_candidates, and I then begin a while loop and use the primes list as a stack, inside the while loop I initialise a list called candidates.

    • I pop off the first element of the primes and call it curr, and then I go through the list of primes and append all primes that are a permutation of curr to candidates

      • After all of this I check if the length of candidates is >= 3, if it is I add the entire list, sorted, to super_candidates

  3. Then I will go through the super_candidates

    • For each list in super_candidates, I find the difference between each term, if I find a list that has 3 different terms whose difference between the largest and middle term is equal to the difference between the middle term and lowest, then I have found a arithmetic sequence, where all terms are prime and permutations of each other!

Interactive Code

No interactive code for this problem, my code is given below