-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathc.lisp
20 lines (17 loc) · 794 Bytes
/
c.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
;; https://code.google.com/codejam/contest/2270488/dashboard#s=p2
(defun split (string)
(loop for i = 0 then (1+ j)
as j = (position #\Space string :start i)
collect (subseq string i j)
while j))
(defun fair-and-square-p (n)
(every #'identity (mapcar (lambda (i)
(let ((s (write-to-string i)))
(equal s (reverse s))))
(list n (* n n)))))
(defun fair-and-squares ()
(let ((limits (mapcar (lambda (n) (sqrt (coerce (parse-integer n) 'double-float))) (split (read-line)))))
(loop for i from (ceiling (first limits)) to (floor (second limits))
count (fair-and-square-p i))))
(dotimes (i (parse-integer (read-line)))
(format t "Case #~a: ~a~%" (1+ i) (fair-and-squares)))