Skip to content

Instantly share code, notes, and snippets.

@SQReder
Created January 6, 2013 04:01
Show Gist options
  • Save SQReder/4465128 to your computer and use it in GitHub Desktop.
Save SQReder/4465128 to your computer and use it in GitHub Desktop.
плющило ночью
(ns your-application
(:use clojure.math.numeric-tower))
;
(defn rndgen_recur [l c n]
(if (= c n)
l
(recur (conj l (rand 10)) (inc c) n)))
(defn rndgen [n]
(rndgen_recur () 0 n))
(defn vector-range [v]
(- (reduce max v) (reduce min v)))
(defn slice_rec [in_data quant normal slices]
(if (empty? in_data)
slices
(let [pos (floor (/ (- (first in_data) normal) quant))]
(let [col (if (= col (count slices)) (dec col) col)]
(recur (rest in_data) quant normal (assoc slices col (inc (get slices col))))))))
(defn slice [vector parts]
(let [slices (vec (repeat parts 0))]
(slice_rec vector (/ (vector-range vector) parts) (reduce min vector) slices)))
(println "sugar " (slice (range -10 10 0.1) 10))
(println "sugar " (slice (rndgen 100) 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment