This post seems to ask just for debugging. The user seems to have thought about the problem, and seems understandably stuck. However, I feel that this question is more suitable for the "stackoverflow" website because it seems to be more about correctness in the coding rather than scientific computing or computational science.
According to the feedback posted on this meta post, I think it falls into the category of "posting lots of code and asking 'debug this' ", but I want to get some feedback from others. Do you feel the same way? Does this question fall within our scope?