Find first n non-repeating objects in a sequence using Clojure

less than 1 minute read

Code

;; first_n_unique_letters.clj

(def string "rgaraga4agjrj4rikllmrfmghjqwwrwengek")

(defn sieve [string]
  (let [first-4-letters (take 4 string)
        unique-letters (set first-4-letters)
        length (count unique-letters)]
    (if (= length 4)
      (clojure.string/join "" first-4-letters)
      (if (= length 0)
        (println "Nothing found")
        (recur (rest string))))))

Notes

Updated: