I have a piece of Clojure code that reverses a string recursively.It is working but too slow (because I got the problem from Codewars and I cannot validate it before it timeouts).The algorithm is :take a string ex. abc and reverse it (r abc) -> cbatake the first position and reverse from there c + (r ba) -> cabtake the second position and reverse from there ca + (r b) -> caband so on..First iteration :(defn reverse-fun [s]  (loop [r s p 0]    (if (= p (count s))      r      (let [[b e] (split-at p r)            e     (reverse e)]        (recur (apply str (concat b e)) (inc p))))))However it was too slow. I pass about 31 tests with this one before the timeout. Here is the fastest I have for now :(defn reverse-fun [s]  (apply str (loop [r (vec s) p 0]               (if (= p (count r))                 r                 (let [b (subvec r 0 p)                       e (rseq (subvec r p (count r)))]                   (recur (into [] (concat b e)) (inc p)))))))This code passes about 72 tests before there is a timeout.How can I make this code faster ?
Clojure reverse multiple times
performance;strings;functional programming;time limit exceeded;clojure
The intermediate reversals seem like a bit of a trick question and are not really necessary to solve this problem. They are a complicated way to describe reordering a sequence indexed0 ... n by taking items n, 0, n-1, 1, n-2, 2 ...alternating from which end you take each time. If you abandon the idea of creating the intermediate strings described it becomes more about how to select the right character from the input string for each position :(ns reversefun.core)(defn reverse-fun [s]  (->> (interleave (reverse s) s)       (take (count s))       (apply str)))