solved intersections in ruby and python