Skip to content

Instantly share code, notes, and snippets.

@deltam
Created January 8, 2011 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deltam/770487 to your computer and use it in GitHub Desktop.
Save deltam/770487 to your computer and use it in GitHub Desktop.
; 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