Created
January 6, 2013 04:01
-
-
Save SQReder/4465132 to your computer and use it in GitHub Desktop.
thtrt
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
(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