P166: Added explanation and comments to Java solution.
P164: Added explanation and comments to Java and Mathematica solutions, tweaked Mathematica solution code, added Haskell solution.