Python and Ruby solutions