Skip to content

Instantly share code, notes, and snippets.

@gsg
Created January 17, 2015 12:08
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 gsg/f8b194b969f26798f327 to your computer and use it in GitHub Desktop.
Save gsg/f8b194b969f26798f327 to your computer and use it in GitHub Desktop.
(defun comb2 (f x y)
(funcall f (+ x y))
(funcall f (- x y))
(funcall f (- y x))
(funcall f (* x y))
(when (not (zerop y))
(funcall f (/ x y)))
(when (not (zerop x))
(funcall f (/ y x))))
(defun comb3 (f x y z)
(comb2 (lambda (q) (comb2 f q z)) x y)
(comb2 (lambda (q) (comb2 f q y)) x z)
(comb2 (lambda (q) (comb2 f q x)) y z))
(defun count-evaluating-to (k x y z)
(let ((count 0))
(comb3 (lambda (n)
(when (= n k)
(incf count)))
x y z)
count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment