Last active
December 9, 2015 15:28
-
-
Save tamamu/1ad22e43bfb6f4e22ea7 to your computer and use it in GitHub Desktop.
paiza「水着」ゲットチャレンジ! をCommonLispで解いてみた.
This file contains hidden or 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
(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