Generate program that has the following intention:

The intention of the program below is to implement a simple Perl 1-like algorithm in Python. The function p1(n) takes an integer argument n and returns the number of set bits (also known as Hamming weight) in the binary representation of n.

Here's an explanation of the code:

1. The while loop runs until n becomes zero.
2. In each iteration, count is incremented by 1.
3. The XOR operation (^=) is used to flip the bits in n at positions where there is a set bit in n - 1. This is done by updating n in place with n ^ (n - 1).
4. After the loop finishes, the count variable contains the number of set bits in n.
5. The function returns count.