A more elegent solution in Ruby ;-)

Maybe Python can do better than this :8ball: