Skip to content

Instantly share code, notes, and snippets.

@fabioyamate
Created April 2, 2013 14:18
Show Gist options
  • Save fabioyamate/5292552 to your computer and use it in GitHub Desktop.
Save fabioyamate/5292552 to your computer and use it in GitHub Desktop.
(def check-sum
(fn [sequence]
(apply + (map (fn [position digit]
(* digit (if (odd? position) 1 3)))
(range 1 (inc (count sequence)))
sequence))))
(defn check-sum-upc [coll]
(apply + (map *
(take (count coll) (cycle '(1 3)))
coll)))
(defn check-sum-upc [coll]
(apply + (map * (cycle '(1 3)) coll)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment