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
vector<int> a{{2,4,6}}; | |
vector<int> b{{1,2,3,4,5}}; | |
vector<int> c{{-1,1-1,1,-1,1,-1,1}}; | |
vector<int> res = map([](int x, int y, int z) {return a*b*c;}, a,b,c); | |
//res -> {-2,8,-18} |
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
(def flip | |
(comp | |
(partial apply comp) | |
reverse | |
(partial list list reverse) | |
(partial partial apply))) | |
(def unspace | |
(partial mapv (comp | |
(partial apply str) |
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 cartesian [coll1 coll2] | |
(for [x coll1 y coll2] | |
[x y])) | |
(defn collapse-if [pred f coll] | |
(->> coll | |
(reduce (fn [processed curr] | |
(let [prev (peek processed)] | |
(if (and prev (pred prev curr)) | |
(conj (pop processed) (f prev curr) nil) |
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 shuffle-with | |
"Returns a random permutation of coll using | |
rng as the random number generator." | |
[^java.util.Random rng | |
^java.util.Collection coll] | |
(let [al (java.util.ArrayList. coll)] | |
(java.util.Collections/shuffle al rng) | |
(clojure.lang.RT/vector (.toArray al)))) | |
(defn rand-with |