I have no problem in implementing this algorithm in any imperative language, but I am struggling implementing it in Clojure or any other functional language. A lot of algorithms are described in terms of working with mutable data structures and imperative loops and it is hard for me to translate all of those to a functional domain.
Here is my incomplete attempt (a draft, not a working implementation) at implementing it in Clojure using adjacency lists as graph representation:
(ns karger.core
(:require [clojure.string :as string]))
(defn load-data []
(zipmap
(range 1 1000)
(map rest (map read-string
(string/split (slurp "data.txt") #"\n")))))
(defn min-cut [graph]
(let [start (rand-int (count graph))
end (rand-int (graph start))
start-list (nth graph start)]
(for [x (graph end)
:when (not= x start)]
(assoc graph start (conj start-list x)))
))
(count (load-data))
Can anyone give me a reference implementation of this algorithm (preferably written in Clojure)? Also I would like if someone gave me a general advice of translating an algorithm described in imperative terms to a functional domain.
Thanks in advance!
UPDATE #1
Here is a link to algorithm implementation written in Python: http://pastebin.com/WwWCtxpu