Skip to content

Instantly share code, notes, and snippets.

@juanibiapina
Last active August 29, 2015 13:57
Show Gist options
  • Save juanibiapina/9667394 to your computer and use it in GitHub Desktop.
Save juanibiapina/9667394 to your computer and use it in GitHub Desktop.
(def :f (function [:x] { (some-other-function x) } ))
(def :collatz (function [:n] { (if (= n 1)
{ (cons 1 nil) }
{ (cons n
(if (even? n)
{ (collatz (/ n 2)) }
{ (collatz (+ (* 3 n) 1)) } )) } )
} ))
(def :collatz-size (function [:n] { (let [:helper { (function [:n :size]
(if (= n 1)
{ (+ 1 size) }
{ (helper (if (even? n)
{ (/ n 2) }
{ (+ (* 3 n) 1) } )
(+ size 1)) } ))
} ]
{ (helper n 0) } )
} ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment