|
|
|
|
|
by dig1
2338 days ago
|
|
I believe I'm missing something here or my day was too long, but in Clojure this can be squeezed in 13 lines and 435 characters keeping things fairly readable (for Clojure & Lisp developers ;)). (defn wc [^String file]
(with-open [rdr (clojure.java.io/reader file)]
(apply (partial printf "%d %d %d\n")
(reduce
(fn [[nl nw nb] ^String ln]
(let [words (count (.split ln "[ ]+"))
bytes (alength (.getBytes ln "UTF-8"))]
[(inc nl) (+ nw words) (+ nb bytes)]))
[0 0 0]
(line-seq rdr)))))
(defn -main [& args]
(wc (first args)))
I haven't tested how fast it is, but startup time can be optimized by compiling it with GraalVM. |
|
You can try this one via Nix with: