Implementing different algorithms in Scala