diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/reverse_sequence.clj	Tue Oct 18 01:17:49 2011 -0700
     1.3 @@ -0,0 +1,36 @@
     1.4 +(ns coderloop.reverse-sequence)
     1.5 +(use 'clojure.contrib.str-utils)
     1.6 +;;(use 'rlm.shell-inspect)
     1.7 +
     1.8 +;(def *command-line-args* (list "/home/ocsenave/reversesequence-a.in"))
     1.9 +(def pairs (if (nil? *command-line-args*) '() (map #(re-split #" " %) (re-split #"\r\n" (slurp (first *command-line-args*))))))
    1.10 +(def p(apply hash-map(reverse(flatten pairs))))
    1.11 +(print(str-join "\n"((fn l[x](if(nil? x)x (cons x(l(p x))) ))
    1.12 +		     (first (remove(set(keys p))(vals p))))) "\n")
    1.13 +
    1.14 +             
    1.15 +
    1.16 +
    1.17 +
    1.18 +
    1.19 +
    1.20 +;; (ns coderloop.reverse-sequence)
    1.21 +;; (use 'clojure.contrib.str-utils)
    1.22 +;; ;;(use 'rlm.shell-inspect)
    1.23 +
    1.24 +;; (defn extension[f ip op] (fn[x](if (= x ip) op (f x))))
    1.25 +
    1.26 +;; (let[
    1.27 +;;      ;;*command-line-args* (list "/home/ocsenave/testfile.txt")
    1.28 +;;      pairs (if (nil? *command-line-args*) '()  (map #(re-split #" " %) (re-split #"\n" (slurp(first *command-line-args*)))))
    1.29 +;;      predecessor (reduce #(extension %1 (second %2)(first %2)) (fn[x]nil) pairs)
    1.30 +;;      terminus (first(remove(set(map first pairs))(map second pairs)))
    1.31 +;;      ]
    1.32 +;;   (defn lineage[x](if(nil? x)nil (cons x(lineage (predecessor x)))))
    1.33 +;;   (print (str-join "\n" (lineage terminus)))
    1.34 +;;   )
    1.35 +
    1.36 +
    1.37 +;;(if (command-line?)
    1.38 +;;  (do-something-to *command-line-args*))
    1.39 +