Attempt to implement basic algorithms with functional programming in scala