Codebook: Shor's Algorithm

Ask here about the “Shor’s Algorithm” Codebook topic from the “Shor’s Algorithm” module.

Hello
I find my implementation of shor algo to be a bit verbose. I wonder if there is a more elegant way to write the nested loops ?

Hi @yoshypdf ,

Our solution doesn’t use nested loops. Just a while loop and a couple of if statements.

Good motivation to keep exploring other ways to solve it! :smiley:

Hej :slight_smile:
I thought I implemented Shor exactly the way you guy stated in your flow chart, and it also prints me the right results. What I am overlooking?


Thanks in advance for every answer! :heart:

Hi @johananasBeere , welcome to the Forum!

It looks like your code doesn’t produce the right result every single time. If you run your code a few times and print the output you’ll see that your output “p” and “q” sometimes don’t actually correspond to the prime factors for N. You can test this for small values of N such as 15 or 21.

This might help you find where you might need to change your algorithm.

1 Like