From b648aa858d4e149048b05f2a99a25c55cc63a063 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Sat, 9 Mar 2013 18:43:26 -0500 Subject: [PATCH] Adding in a port of Dan Gulotta's "The Halting Problem" .clj script. --- eg/nonfree/halting-problem/halting.hy | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 eg/nonfree/halting-problem/halting.hy diff --git a/eg/nonfree/halting-problem/halting.hy b/eg/nonfree/halting-problem/halting.hy new file mode 100644 index 0000000..b8060f0 --- /dev/null +++ b/eg/nonfree/halting-problem/halting.hy @@ -0,0 +1,21 @@ +; Very much a knockoff (straight port) of Dan Gulotta's 2013 MIT Mystery Hunt +; puzzle "The Halting Problem". + + +(defn evaluate [f] ((f (lambda [x] (+ x 1))) 0)) + +(defn successor [n] (lambda [f] (lambda [x] (f ((n f) x))))) +(defn plus [m n] ((n successor) m)) +(defn exponent [m n] (n m)) +(defn zero [f] (lambda [x] x)) +(defn one [f] (lambda [x] (f x))) + +(defn predecessor [n] (lambda [f] (lambda [x] + (((n (lambda [g] (lambda [h] (h (g f))))) (lambda [y] x)) (lambda [z] z))))) + +(defn subtract [m n] ((m predecessor) n)) + +(def two (plus one one)) +(def three (plus two one)) + +(print (evaluate (exponent three three)))