News for hackers. Stuff that matters.
Re:Google CEO says more than a quarter of the company's new ... by justinpombrio on Wednesday October 30, 2024 @05:58PM (#42000890)
> Can you spot all the problems?

You were probably being rhetorical, but there are two problems:

- `p = 2` should be outside the loop

- `prime_factors.append(n)` appends `1` onto the end of the list for no reason

With those two changes I'm pretty sure it's correct.

Re:Google CEO says more than a quarter of the company's new ... by rmbyrro on Wednesday October 30, 2024 @07:44PM (#42001854)
`n` isn't defined
Re:Google CEO says more than a quarter of the company's new ... by justinpombrio on Wednesday October 30, 2024 @09:50PM (#42002630)
The implicit context that the poster removed (as you can tell from the indentation) was a function definition:

    def factorize(n):
      ...
      return prime_factors
Re:Google CEO says more than a quarter of the company's new ... by kenjackson on Wednesday October 30, 2024 @10:45PM (#42002950)
You don't need to append 'p' in the inner while loop more than once. Maybe instead of an array for keeping the list of prime factors do it in a set.
Re:Google CEO says more than a quarter of the company's new ... by zeroonetwothree on Thursday October 31, 2024 @12:48AM (#42003601)
It’s valid to return the multiplicity of each prime, depending on the goal of this.
Re:Google CEO says more than a quarter of the company's new ... by justinpombrio on Thursday October 31, 2024 @11:04AM (#42007640)