summaryrefslogtreecommitdiff
path: root/gcd.lisp
diff options
context:
space:
mode:
authorIgor <pashev.igor@gmail.com>2011-01-26 00:28:50 +0300
committerIgor <pashev.igor@gmail.com>2011-01-26 00:28:50 +0300
commit0d3412d3ef23c30d1212ef92b3cb7c1453236102 (patch)
treecbb8b093fc1fdf9632d44add6101a0b74a36b436 /gcd.lisp
parent4f174764f3e4d12747e9bc2938fb43aafcf5358c (diff)
downloadgcd-0d3412d3ef23c30d1212ef92b3cb7c1453236102.tar.gz
Common Lisp
Diffstat (limited to 'gcd.lisp')
-rw-r--r--gcd.lisp24
1 files changed, 24 insertions, 0 deletions
diff --git a/gcd.lisp b/gcd.lisp
new file mode 100644
index 0000000..831bb31
--- /dev/null
+++ b/gcd.lisp
@@ -0,0 +1,24 @@
+(defun gcd2 (a b)
+ (if (= b 0)
+ a
+ (gcd2 b (mod a b))))
+
+(defun gcdn (&rest numbers)
+ (reduce #'gcd2 (rest numbers)
+ :initial-value (first numbers)))
+
+; Command line access is different on different Lisps
+(defun program-args ()
+ (or
+ #+SBCL (rest *posix-argv*)
+ #+CLISP *args*
+ ;#+ECL (ext:command-args)
+ ;#+CMU extensions:*command-line-words*
+ ;#+LISPWORKS system:*line-arguments-list*
+ nil))
+
+(write (apply #'gcdn
+ (map 'list #'parse-integer (program-args))
+ ))
+(fresh-line)
+