translating yuris solution from python to ruby