finish HW2.

It's not a perfect match with the output of the reference code. I
believe this is caused by float point operation. I need to double
check and confirm that later.