Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Cassidy's Interview Question - 04/05/2020
(def default-input ["candy" "doodle" "pop" "shield" "lag" "typewriter" "this"])
(def qwerty-rows ["qwertyuiop" "asdfghjkl" "zxcvbnm"])
(def dvorak-rows ["pyfgcrl" "aoeuidhtns" "qjkxbmwvz"])
(def azerty-rows ["azertyuiop" "qsdfghjklm" "wxcvbn"])
(defn get-letter-row
"Returns the index of the row in which the letter is present"
[letter layout]
(loop [current-row (first layout)
rest-elems (rest layout)
current-index 0]
(if (clojure.string/index-of current-row letter)
(recur (first rest-elems) (rest rest-elems) (inc current-index)))))
(defn get-num-str
"Returns a collection of the row of each letter present in the word"
[word layout]
(map #(get-letter-row % layout) (clojure.string/split word #"")))
(defn one-row
"Returns the collection of words in the input that can be entered on the same row"
[coll layout]
(filter #(apply = (get-num-str % layout)) coll))
(defn program
"Outputs the result for multiple layouts instead of seeking user input
First is qwerty
Second is dvorak
Third is azerty"
(doseq [current-layout [qwerty-rows dvorak-rows azerty-rows]]
(println (one-row input current-layout))))
(program default-input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment