Algorithms using scala