my implementation of DPA algorithm (buggy)