Created
January 10, 2011 05:24
-
-
Save hso/772411 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup Double Squares
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)))) | |
(defparameter *numbers* (mapcar #'read-from-string (cdr *lines*))) | |
(defun perfectp (x) | |
(zerop (mod (sqrt x) 1))) | |
(defun expressions (n) | |
(loop for i from 0 to (truncate (sqrt (/ n 2))) | |
count (perfectp (- n (expt i 2))))) | |
(with-open-file (out "output.txt" | |
:direction :output | |
:if-exists :supersede) | |
(with-standard-io-syntax | |
(format out "~{~a~%~}" (mapcar #'expressions *numbers*)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment