write classical algorithme in beautifule ruby code