rlm@0: (ns coderloop.reverse-sequence) rlm@0: (use 'clojure.contrib.str-utils) rlm@0: ;;(use 'rlm.shell-inspect) rlm@0: rlm@0: ;(def *command-line-args* (list "/home/ocsenave/reversesequence-a.in")) rlm@0: (def pairs (if (nil? *command-line-args*) '() (map #(re-split #" " %) (re-split #"\r\n" (slurp (first *command-line-args*)))))) rlm@0: (def p(apply hash-map(reverse(flatten pairs)))) rlm@0: (print(str-join "\n"((fn l[x](if(nil? x)x (cons x(l(p x))) )) rlm@0: (first (remove(set(keys p))(vals p))))) "\n") rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: ;; (ns coderloop.reverse-sequence) rlm@0: ;; (use 'clojure.contrib.str-utils) rlm@0: ;; ;;(use 'rlm.shell-inspect) rlm@0: rlm@0: ;; (defn extension[f ip op] (fn[x](if (= x ip) op (f x)))) rlm@0: rlm@0: ;; (let[ rlm@0: ;; ;;*command-line-args* (list "/home/ocsenave/testfile.txt") rlm@0: ;; pairs (if (nil? *command-line-args*) '() (map #(re-split #" " %) (re-split #"\n" (slurp(first *command-line-args*))))) rlm@0: ;; predecessor (reduce #(extension %1 (second %2)(first %2)) (fn[x]nil) pairs) rlm@0: ;; terminus (first(remove(set(map first pairs))(map second pairs))) rlm@0: ;; ] rlm@0: ;; (defn lineage[x](if(nil? x)nil (cons x(lineage (predecessor x))))) rlm@0: ;; (print (str-join "\n" (lineage terminus))) rlm@0: ;; ) rlm@0: rlm@0: rlm@0: ;;(if (command-line?) rlm@0: ;; (do-something-to *command-line-args*)) rlm@0: