some algorithms in scala