P37: Simplified and tweaked Java solution.
P11: Added Mathematica solution.
P14: Added Mathematica solution.