Guest User

Untitled

a guest
Dec 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. (ns lisp.core
  2. (:gen-class)
  3. (:require [clojure.string :as s]))
  4.  
  5. (defn -main
  6. "I don't do a whole lot ... yet."
  7. [& args]
  8. (println "Hello, World!"))
  9.  
  10. (map inc (range 10))
  11. ;; => (1 2 3 4 5 6 7 8 9 10)
  12.  
  13. (def f
  14. (as-> (slurp "/Users/tommy/programming/pscsta/student_data/fezr.in") x
  15. (s/split x #"\s+")
  16. (rest x)
  17. (map read-string x)))
  18.  
  19.  
  20.  
  21. (s/join ", " f)
  22. ;; => "1, 258, 304, 2, 1014, 1019, 1017, 1024, 4, 3, 7, 6, 9, 502, 502, 3512, 3519, 2, 2384, 2407, 1756, 1766, 3, 684, 702, 702, 721, 784, 789"
  23.  
  24.  
  25.  
  26. (defn read [[head & rest]]
  27. (if head
  28. (cons (take (* 2 head) rest)
  29. (read (drop (* 2 head) rest)))
  30. nil))
  31. (defn printn [s]
  32. (for [x s]
  33. (println x)))
  34.  
  35. (println "---")
  36. (range 1 5)
  37.  
  38. (printn) (for [x (read f)]
  39. (count
  40. (distinct
  41. (flatten
  42. (map (fn [[a b]] (range a (inc b)))
  43. (partition 2 x))))))
  44. ;; => (47 11 16 35 44)
Add Comment
Please, Sign In to add comment