annotate src/reverse_sequence.clj @ 0:307a81e46071 tip

initial committ
author Robert McIntyre <rlm@mit.edu>
date Tue, 18 Oct 2011 01:17:49 -0700
parents
children
rev   line source
rlm@0 1 (ns coderloop.reverse-sequence)
rlm@0 2 (use 'clojure.contrib.str-utils)
rlm@0 3 ;;(use 'rlm.shell-inspect)
rlm@0 4
rlm@0 5 ;(def *command-line-args* (list "/home/ocsenave/reversesequence-a.in"))
rlm@0 6 (def pairs (if (nil? *command-line-args*) '() (map #(re-split #" " %) (re-split #"\r\n" (slurp (first *command-line-args*))))))
rlm@0 7 (def p(apply hash-map(reverse(flatten pairs))))
rlm@0 8 (print(str-join "\n"((fn l[x](if(nil? x)x (cons x(l(p x))) ))
rlm@0 9 (first (remove(set(keys p))(vals p))))) "\n")
rlm@0 10
rlm@0 11
rlm@0 12
rlm@0 13
rlm@0 14
rlm@0 15
rlm@0 16
rlm@0 17 ;; (ns coderloop.reverse-sequence)
rlm@0 18 ;; (use 'clojure.contrib.str-utils)
rlm@0 19 ;; ;;(use 'rlm.shell-inspect)
rlm@0 20
rlm@0 21 ;; (defn extension[f ip op] (fn[x](if (= x ip) op (f x))))
rlm@0 22
rlm@0 23 ;; (let[
rlm@0 24 ;; ;;*command-line-args* (list "/home/ocsenave/testfile.txt")
rlm@0 25 ;; pairs (if (nil? *command-line-args*) '() (map #(re-split #" " %) (re-split #"\n" (slurp(first *command-line-args*)))))
rlm@0 26 ;; predecessor (reduce #(extension %1 (second %2)(first %2)) (fn[x]nil) pairs)
rlm@0 27 ;; terminus (first(remove(set(map first pairs))(map second pairs)))
rlm@0 28 ;; ]
rlm@0 29 ;; (defn lineage[x](if(nil? x)nil (cons x(lineage (predecessor x)))))
rlm@0 30 ;; (print (str-join "\n" (lineage terminus)))
rlm@0 31 ;; )
rlm@0 32
rlm@0 33
rlm@0 34 ;;(if (command-line?)
rlm@0 35 ;; (do-something-to *command-line-args*))
rlm@0 36