comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:307a81e46071
1 (ns coderloop.reverse-sequence)
2 (use 'clojure.contrib.str-utils)
3 ;;(use 'rlm.shell-inspect)
4
5 ;(def *command-line-args* (list "/home/ocsenave/reversesequence-a.in"))
6 (def pairs (if (nil? *command-line-args*) '() (map #(re-split #" " %) (re-split #"\r\n" (slurp (first *command-line-args*))))))
7 (def p(apply hash-map(reverse(flatten pairs))))
8 (print(str-join "\n"((fn l[x](if(nil? x)x (cons x(l(p x))) ))
9 (first (remove(set(keys p))(vals p))))) "\n")
10
11
12
13
14
15
16
17 ;; (ns coderloop.reverse-sequence)
18 ;; (use 'clojure.contrib.str-utils)
19 ;; ;;(use 'rlm.shell-inspect)
20
21 ;; (defn extension[f ip op] (fn[x](if (= x ip) op (f x))))
22
23 ;; (let[
24 ;; ;;*command-line-args* (list "/home/ocsenave/testfile.txt")
25 ;; pairs (if (nil? *command-line-args*) '() (map #(re-split #" " %) (re-split #"\n" (slurp(first *command-line-args*)))))
26 ;; predecessor (reduce #(extension %1 (second %2)(first %2)) (fn[x]nil) pairs)
27 ;; terminus (first(remove(set(map first pairs))(map second pairs)))
28 ;; ]
29 ;; (defn lineage[x](if(nil? x)nil (cons x(lineage (predecessor x)))))
30 ;; (print (str-join "\n" (lineage terminus)))
31 ;; )
32
33
34 ;;(if (command-line?)
35 ;; (do-something-to *command-line-args*))
36