Classic algorithms in Scala