Skip to content

Instantly share code, notes, and snippets.

@ashnur
Created December 15, 2016 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashnur/af62ecc560ed167248f47b9037e99955 to your computer and use it in GitHub Desktop.
Save ashnur/af62ecc560ed167248f47b9037e99955 to your computer and use it in GitHub Desktop.
(ns combo-network.graph)
(defn seed
[init-nodes-count]
(range 0 init-nodes-count))
;; initial-contacts (select-random seed-nodes)
;; secondary-contact (select)
(defn grow-step [graph]
(let [nodes (:nodes graph)
edges (:edges graph)]
{:nodes (conj nodes (+ (apply max nodes) 1))
:edges edges}))
(defn grow [& args]
(apply (fn step [pred x]
(let [y (grow-step x)]
(js/console.log (pred y) y)
(if (pred y)
(fn [] (step pred y))
y))) args))
(defn grow-graph-to-size [graph final-size]
(trampoline grow #(> final-size (count (:nodes %))) graph))
(defn graph [init-nodes-count final-size]
(let [seed-nodes (seed init-nodes-count)]
(grow-graph-to-size {:nodes seed-nodes :edges []} final-size)))
(js/console.log (graph 1 5)) ;; {:nodes (4 3 2 1 0) , :edges []}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment