Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Last active March 14, 2016 12:42
Show Gist options
  • Save chrisguitarguy/0a18292245ad05bfdec1 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/0a18292245ad05bfdec1 to your computer and use it in GitHub Desktop.
(defn perceptron [inputs weights bias]
{:pre [(= (count inputs) (count weights))]}
(let [combined (map * inputs weights)]
(if (< (+ (apply + combined) bias) 1) 0 1)))
(defn nand [one two]
(perceptron [one two] [-2 -2] 3))
(defn adder [x y]
"Returns a vector of [carry-bit sum-bit]"
(let [f (nand x y)
s (nand f f)]
[s (nand (nand x f) (nand s f))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment