Created
January 8, 2011 02:55
-
-
Save deltam/770487 to your computer and use it in GitHub Desktop.
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
; int-calc.clj | |
(ns int-calc | |
(:use [clojure.contrib.command-line :only (with-command-line)])) | |
(with-command-line *command-line-args* | |
"clj int-calc.clj [-p|-mi|-ml] [-modulo n] nums.." | |
[[plus? p? "plus" true] | |
[minus? mi? "minus"] | |
[multiply? ml? "multiply"] | |
[modulo "mod n"] | |
num-strs] | |
(let [nums (map #(Integer/parseInt %) num-strs) | |
func (cond | |
plus? + | |
minus? - | |
multiply? *) | |
result (reduce func nums)] | |
(if (nil? modulo) | |
(println result) | |
(println (mod result (Integer/parseInt modulo)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment