converting my clojure solution to Scala