Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Do you mean that I should put the "doseq" in the "deftest"?
There are randomized tests that are pregenerated, as described in the comment:
; these are were generated offline as random string creation is very time consuming in clojure
; they are based on C++'s algorithm as follows:
; first and last cells are always clear, maze size between 4 and 11 (not including line breaks), 1 out of 3 chance for a wall
I've added the code I'm using for maze creation to the tests also.
(defn random-maze-builder
[size]
(let [maze-size (+ size (* size size))
break-idx (+ size 1)]
(str
(reduce
(fn [maze idx]
(let [next (cond
(= idx 1) "."
(= (mod idx break-idx) 0) "\n"
(= idx (- maze-size 1)) "."
:else (if (= 0 (rand-int 3))
"W"
"."))]
(.append maze next)))
(StringBuilder. maze-size)
(range 1 maze-size)))))
Wow I wasn't aware it would be twice as fast with mapv!
Thanks, this is a tip to remember.
Fixed the comparator, unless I'm missing something additional (in case I'd appriciate you'd point out)
Could you please elaborate? When I tested it, it worked fine
Having the frequencies call within the every makes it an O(n^2), so it's probably better to calculate them ahead of time
Saying what's the issue with this solution would be much more helpful than just saying "is terrible"
Original signature is "std::string DNAStrand(const std::string& dna)" in which you can't change dna because of the "const"
You should probably "dedupe" only after the sort, as there is no promise array1 is sorted
Using "replace-first" misleads the code reader about you're trying to do, and adds un-needed steps, you could use "includes?" instead
In "substring-of-any?" you could use "when" instead of "if"