Skip to main content
3 of 3
Commonmark migration

Clojure, 69 66 bytes

#(let[s(apply str(sort %))](or(= % s)(= %(apply str(reverse s))))) 

-3 by inlining reversed.

My original try ended up being a longer version of the other Clojure answer, so I went the "sorted" route. Checks if the original string is equal to a sorted version of itself, or a reversed sorted string. Amazingly, (apply str (reverse s) ended up being shorter than using the built-in reverse string method.

(defn lex? [s] ; (apply str ...) basically just turns a list into a string (let [sorted (apply str (sort s)) reversed (apply str (reverse sorted))] (or (= s sorted) (= s reversed)))) 
Carcigenicate
  • 3.6k
  • 2
  • 23
  • 31