Skip to content

Instantly share code, notes, and snippets.

@tamamu
Last active December 9, 2015 15:28
Show Gist options
  • Save tamamu/1ad22e43bfb6f4e22ea7 to your computer and use it in GitHub Desktop.
Save tamamu/1ad22e43bfb6f4e22ea7 to your computer and use it in GitHub Desktop.
paiza「水着」ゲットチャレンジ! をCommonLispで解いてみた.
(defun get-input ()
(parse-integer (read-line)))
(defun factorial (n)
(if (<= n 1)
1
(* n (factorial (1- n)))))
(defun trim-zero-right (s)
(if (eq (elt s (1- (length s))) #\0)
(trim-zero-right (subseq s 0 (1- (length s))))
s))
(defun nine-tail (s)
(if (<= (length s) 9)
s
(subseq s (- (length s) 9) (length s))))
(defun trim-zero-left (s)
(if (eq (elt s 0) #\0)
(trim-zero-left (subseq s 1 (length s)))
s))
(defun main ()
(princ (trim-zero-left
(nine-tail
(trim-zero-right
(write-to-string
(factorial (get-input))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment