P429: Added Mathematica solution, tweaked Java solution.