programming kata

1 minute read

Code kata

Problem Implement take-nth. Solutions Solution 1 (defn my-take-nth [n col] (loop [i 0 result []] (if (= i (count col)) result (if (= 0 (mod i n)) (recur (inc i) (conj result (nth col i))) (recur (inc i) result))))) solution 2 (defn my-take-nth2 [n col] (->> col (map-indexed (fn [i x] [i x])) (filter (fn [[i x]] (= 0 (mod i 2)))) (mapv (fn [[i x]] x))))

1 minute read

Code kata

Problem Trolls are attacking your comment section! A common way to deal with this situation is to remove all of the vowels from the trolls' comments, neutralizing the threat. Your task is to write a function that takes a string and return a new string with all vowels removed. For example, the string “This website is for losers LOL!” would become “Ths wbst s fr lsrs LL!”. Solution Solution 1 (defn disemvowel [string] (reduce (fn [result next] (if (#{\A \E \I \O \U \a \e \i \o \u} next) result (str result next))) "" string)) Solution 2 (defn disemvowel [string] (apply str (remove (set "AEIOUaeiou") string)))

1 minute read

Code kata

From today, I will practice one programming kata per day and post the content here. Here goes the first one: My friend John likes to go to the cinema. He can choose between system A and system B. System A : buy a ticket (15 dollars) every time System B : buy a card (500 dollars) and every time buy a ticket the price of which is 0.

5 minute read

I suck at algorithms, even though I have a Machine Learning and Algorithms master degree. It makes me frown everytime in coding interviews. So I decided to practice more often, hope that I can get better at it. At least not afraid of it. Now this is the first one. Problem Rotate a square matrix clockwise concentrically by 1. For example: 1 2 3 4 5 6 7 8 9 will become