;; (isosceles-p 424) ;=> T
(defun isosceles-p (a b c)
(or (= a b) (= a c) (= b c)))
(defun print-yesno (c)
(declare (type boolean c))
(princ (if c "Yes""No")))
(defun main ()
(print-yesno (isosceles-p (read) (read) (read))))
#-swank(main)Code language:PHP(php)
;; (elected-name '("x" "y" "xx" "y" "z")) ; => "y"
(defun elected-name (names)
(let ((ht (make-hash-table :test #'equal)))
(loop for name in names
do (setf (gethash name ht 0)
(1+ (gethash name ht 0))))
(loop for name being each hash-key of ht
using (hash-value voted)
with max = 0
with result = ""
when (< max voted)
do (setf result name)
(setf max voted)
finally (return result))))
(defun main ()
(let* ((n (read))
(names (loop repeat n collect (read-line))))
(princ (elected-name names))))
#-swank(main)Code language:PHP(php)
(defun same-name-p (names)
(let ((ht (make-hash-table :test #'equal)))
(loop for name in names
do (setf (gethash name ht 0)
(1+ (gethash name ht 0))))
(loop for name being each hash-key of ht
using (hash-value number)
thereis (>= number 2))))
;; (same-names '("tanaka taro" "sato hanako" "tanaka taro")) ;=> T
(defun print-yesno (c)
(declare (type boolean c))
(princ (if c "Yes" "No")))
(defun main ()
(let* ((n (read))
(names (loop repeat n collect n)))
(print-yesno (same-name-p names))))
#-swank(main)
Code language:PHP(php)
(defun read-lines (N)
(loop for row below N
collect (read-line)))
(defun make-grid (N lines)
(let ((grid (make-array (list N N)
:element-type 'character
:initial-element #\.)))
(loop for row below N
for line in lines
do (loop for ch across line
for col below N
do (setf (aref grid row col) ch))
finally (return grid))))
(defun make-grid (N lines)
(let ((grid (make-array (list N N)
:element-type 'character
:initial-element #\.)))
(loop for row below N
for line in lines
do (loop for ch across line
for col below N
do (setf (aref grid row col) ch))
finally (return grid))))
(defun copy-grid! (N from to)
(loop for row below N
do (loop for col below N
do (setf (aref to row col)
(aref from row col)))
finally (return to)))
(defun manipulate! (N grid temp i)
(copy-grid! N grid temp)
(loop for x from i to (+ N 1 (- i))
do (loop for y from i to (+ N 1 (- i))
do (setf (aref grid (1- y) (- N x))
(aref temp (1- x) (1- y)))))
grid)
(defun manipulate-times! (N grid)
(let ((temp (make-array (list N N)
:element-type 'character
:initial-element #\.)))
(loop for i from 1 to (floor N 2)
do (manipulate! N grid temp i))
grid))
(defun print-grid (N grid)
(loop for x from 1 to N
do (loop for y from 1 to N
do (princ (aref grid (1- x) (1- y))))
(terpri)))
(defun main ()
(let* ((n (read))
(lines (read-lines n))
(grid (make-grid n lines))
)
(print-grid n (manipulate-times! n grid))))
#-swank(main)
Code language:PHP(php)