Text processing/Max licenses in use: Difference between revisions

No edit summary
Line 614:
GOBACK
.</lang>
 
=={{header|Clojure}}==
 
<lang clojure>(defn delta
"Determines if the number of licences out should be increased or decreased
according to an entry."
[entry]
(case (second (re-find #"\ (.*)\ @" entry))
"IN " -1
"OUT" 1
(throw (Exception. (str "Invalid entry:" entry)))))
 
(defn time
"Extracts the time component of an entry."
[entry]
(second (re-find #"@\ (.*)\ f" entry)))
 
(defn process
"Builds a map where keys are the number of licences out and the values are the
times where we reached that number."
[entries]
(first
(reduce
(fn [[m last] entry]
(let [new (+ (delta entry) last)]
[(update m new concat [(time entry)])
new]))
[{} 0] entries)))
 
(let [data (process (clojure.string/split (slurp "mlijobs.txt") #"\n"))
m (apply max (keys data))]
(println "Maximum simultaneous license use is" m "at the following times:")
(map println (data m)))</lang>
 
<pre>> (max-licenses)
Maximum simultaneous license use is 99 at the following times:
2008/10/03_08:39:34
2008/10/03_08:40:40
</pre>
 
=={{header|Common Lisp}}==