Skip to content

Instantly share code, notes, and snippets.

@hso
Created January 10, 2011 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hso/772432 to your computer and use it in GitHub Desktop.
Save hso/772432 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup Studious Student
(defparameter *lines* (with-open-file (in "input.txt")
(loop for line = (read-line in nil nil)
while line
collect line into lines
finally (return lines))))
(defun read-words (str)
(cdr (read-from-string
(format nil "(~a)" str))))
(defun cat (w1 w2)
(format nil "~a~a" w1 w2))
(defun word< (w1 w2)
(string< (cat w1 w2) (cat w2 w1)))
(defun build-string (lst)
(format nil "~{~(~a~)~}" (sort lst 'word<)))
(with-open-file (out "output.txt"
:direction :output
:if-exists :supersede)
(with-standard-io-syntax
(format out "~{~a~%~}" (mapcar #'build-string
(cdr (mapcar #'read-words
*lines*))))))
@dmitrysobolev
Copy link

What language it is?

@hso
Copy link
Author

hso commented Jan 10, 2011

It's Common Lisp. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment