Created
January 28, 2012 16:57
-
-
Save martintrojer/1695009 to your computer and use it in GitHub Desktop.
poems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn fib [n] | |
(loop [back1 1, back2 0, n n] | |
(cond | |
(= n 0) 0 | |
(= n 1) (+ back1 back2) | |
:else (recur back2 (+ back1 back2) (- n 1))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fib n = | |
let rec fib' back1 back2 = function | |
| 0 -> 0 | |
| 1 -> back1 + back2 | |
| n -> fib' back2 (back1 + back2) (n - 1) | |
fib' 1 0 n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn qsort [[pivot & xs]] | |
(when pivot | |
(let [{smaller true bigger false} (group-by #(< % pivot) xs)] | |
(lazy-cat (qsort smaller) [pivot] (qsort bigger))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn qsort [[pivot & xs]] | |
(when pivot | |
(let [smaller #(< % pivot)] | |
(lazy-cat (qsort (filter smaller xs)) | |
[pivot] | |
(qsort (remove smaller xs)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec sort = function | |
| [] -> [] | |
| h::t -> | |
let less, greater = List.partition ((>) h) t | |
sort less @ h :: sort greater |
Re: alex Thanks man, very nice :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I slightly modified the clojure version to make it look more like a Haskell one.