"Are you asking for a challenge???!!"
Mar. 26th, 2004 02:36 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
For all j00 l337 hackers out there...
Choose your favourite language; how many lines and how many minutes does it take you to write a program that takes in an arbitrary text file, find all the unique words in it, and spit them back?
(I had need to do this, just a few minutes ago, and I did it in like 20 very calm, relaxed lines of LISP, in just a coupla minutes... but I bet if you're good at Perl, you could do it in fewer lines and fewer minutes than that)
Post source :)
Choose your favourite language; how many lines and how many minutes does it take you to write a program that takes in an arbitrary text file, find all the unique words in it, and spit them back?
(I had need to do this, just a few minutes ago, and I did it in like 20 very calm, relaxed lines of LISP, in just a coupla minutes... but I bet if you're good at Perl, you could do it in fewer lines and fewer minutes than that)
Post source :)
(load "ci-utils.lisp") ;; for macros get-hash-keys and dolines (defvar *words* (make-hash-table :test #'equal)) (defun populate-words (filename) (dolines (line filename) (loop for word in (getwords line) do (setf (gethash word *words*) t)))) (defun getwords (line) (read-from-string (format nil "(~a)" (strip-period line)))) (defun strip-period (str) (string-trim "." str)) (defun list-of-words () (get-hash-keys *words*)) (defun print-all-words () (loop for word in (list-of-words) do (format t "~a~%" word)))
no subject
Date: 2004-03-26 02:55 pm (UTC)I'm trying to conceptualize how you'd do this in 1 line of Perl, because, you know, Everything Can Be Reduced To One Line Of Perl, but it might be a very long one...