diff options
| author | Fung Cheok Yin <61836418+E7-87-83@users.noreply.github.com> | 2020-08-10 00:09:08 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-10 00:09:08 +0800 |
| commit | cd819ee85e2758e1a02e08ba45f8c8de08a85a5d (patch) | |
| tree | 7941c7bb1523227664e6e4630d8761676a49d7a7 | |
| parent | 4fb8f59eadd9ce4ca21fa136d9475bc1a1953d8a (diff) | |
| download | perlweeklychallenge-club-cd819ee85e2758e1a02e08ba45f8c8de08a85a5d.tar.gz perlweeklychallenge-club-cd819ee85e2758e1a02e08ba45f8c8de08a85a5d.tar.bz2 perlweeklychallenge-club-cd819ee85e2758e1a02e08ba45f8c8de08a85a5d.zip | |
Create ch-1.lsp
| -rw-r--r-- | challenge-072/cheok-yin-fung/common-lisp/ch-1.lsp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-072/cheok-yin-fung/common-lisp/ch-1.lsp b/challenge-072/cheok-yin-fung/common-lisp/ch-1.lsp new file mode 100644 index 0000000000..66b8568394 --- /dev/null +++ b/challenge-072/cheok-yin-fung/common-lisp/ch-1.lsp @@ -0,0 +1,36 @@ +; Perl Weekly Challenge #072 Task 1 Trailing Zeroes +; The following Lisp code use a primitive method +; to count the trailing zeroes + +(defun fact (num) + (cond ((equal 1 num) 1) + ((> num 1) (* (fact (- num 1)) num)) + ) +)) + + +(defun countzero (num) + (if (zerop (mod num 10)) (+ 1 (countzero (/ num 10) )) + '0 +)) + +(defun tzero (n) + (countzero (fact n)) +) + +(tzero 10) ; output 2 + +(tzero 7) ; output 1 + +(tzero 4) ; output 0 + +(tzero 25) ; output 6 + +(tzero 30) ; output 7 + +(tzero 50) ; output 12 + +(tzero 100) ; output 24 + + +; values larger than 5327 give "Program stack overflow "; GNU CLISP 2.49.60+ |
