alexr_rwx: (my fandom writes your software)
[personal profile] alexr_rwx
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 :)


(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)))

Date: 2004-03-26 02:55 pm (UTC)
ext_110843: (withtux)
From: [identity profile] oniugnip.livejournal.com
I'd be impressed :)

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...

Profile

alexr_rwx: (Default)
Alex R

May 2022

S M T W T F S
1234 567
891011121314
15161718192021
22232425262728
293031    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 7th, 2025 02:03 pm
Powered by Dreamwidth Studios