-
-
Save anonymous/96404337149c10c52439 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn- arr-partition-approx | |
"Splits `arr` into arrays of size between min-len and max-len, | |
trying to stick to (min+max)/2" | |
[min-len max-len arr] | |
(let [chunk-len (half (+ max-len min-len)) | |
len (count arr)] | |
(when (pos? len) | |
(loop [acc [], len len, arr arr] | |
(cond | |
(<= len max-len) | |
(conj acc arr) | |
(>= len (+ chunk-len min-len)) | |
(let [[lhs rhs] (split-at chunk-len arr)] | |
(recur (conj acc lhs) (- len chunk-len) rhs)) | |
:else | |
(let [piece-len (half len) | |
[lhs rhs] (split-at piece-len arr)] | |
(recur (conj acc lhs) (- len piece-len) rhs))))))) | |
(doseq [n (range 0 256 16) | |
:let [res (arr-partition-approx min-len max-len (range n))]] | |
(println (map count res)) | |
(assert (= (range n) (flatten res)) (pr-str res))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cratch.clj:14 recur arg for primitive local: len is not matching primitive, had: Object, needed: long | |
scratch.clj:18 recur arg for primitive local: len is not matching primitive, had: Object, needed: long | |
Auto-boxing loop arg: len |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment