Last active
April 7, 2021 20:37
-
-
Save slifin/f239b4a4b09e77cd1f56a03d6281d04b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns BristolClojurians.interview | |
(:require [clojure.test :refer [deftest is]]) | |
(:gen-class)) | |
;; set is allowed | |
(defn unique? [string] | |
(= string (apply str (set string)))) | |
(deftest unique?-test | |
(is (= true (unique? "abc"))) | |
(is (= false (unique? "test")))) | |
(defn unique-loop? [string] | |
(loop [acc [] | |
word string] | |
(cond | |
(empty? word) true | |
(some (partial = (first word)) acc) false | |
:else (recur (conj acc (first word)) (rest word))))) | |
(deftest unique-loop?-test | |
(is (= (unique-loop? "") true)) | |
(is (= (unique-loop? "abc") true)) | |
(is (= (unique-loop? "test") false))) | |
(defn unique-frequencies? [string] | |
(filter #{1 0} (frequencies string))) | |
(comment | |
(mapv (comp #(< % 2) val) (frequencies "test"))) | |
(comment | |
(apply max (mapv val (frequencies "test")))) | |
(comment | |
(boolean (seq (filter (comp #(<= 2 %) val) (frequencies "tes"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment