Skip to content

Instantly share code, notes, and snippets.

@RussellAndrewEdson
Created April 11, 2015 01:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RussellAndrewEdson/55bd57a00da07f7c8243 to your computer and use it in GitHub Desktop.
Save RussellAndrewEdson/55bd57a00da07f7c8243 to your computer and use it in GitHub Desktop.
The recursive F and M functions from Godel, Escher, Bach.
(declare f m)
(defn f
"The F function from Godel, Escher, Bach: takes in
an integer n and returns F(n) = n - M(F(n-1)), with F(0) = 1."
[n]
(if (= n 0)
1
(- n (m (f (- n 1))))))
(defn m
"The M function from Godel, Escher, Bach: takes in
an integer n and returns M(n) = n - F(M(n-1)), with M(0) = 0."
[n]
(if (= n 0)
0
(- n (f (m (- n 1))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment