|
|
|
|
|
by itishappy
657 days ago
|
|
Honestly both read about the same to me, and I'm largely unfamiliar with Clojure. The main difference appears to be the 3 `str` callouts, which appear extraneous as the following version works just the same: (defn color [word letter idx]
(cond
(= (nth word idx) letter) :green
(str/includes? word letter) :yellow
:else :gray))
Interesting that even with the `str` callouts removed, the function still appears to work on other datatypes such as: (def s (seq ("test1"))
A lazy sequence, but one Clojure still allows to be indexed over in O(1) time. That's probably what the `str` conversion was trying to speed up.Python, meanwhile, fails on lazy input as it isn't indexable. word = (c for c in "test1")
I guess I'll be checking out Clojure this weekend. |
|
Or possibly the code even uses non-symbols for some of the arguments. Suppose that letter is sometimes the integer 1.