Add #12 solutions in Python and Ruby