Created
January 10, 2011 05:57
-
-
Save hso/772432 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup Studious Student
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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*)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What language it is?