/l99
Created
August 23, 2011 02:25
Revisions
-
ujihisa created this gist
Aug 23, 2011 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ (defn my-last [xs] (cond (empty? (rest xs)) (first xs) :otherwise (recur (rest xs)))) (println (my-last '(a b c d))) (defn my-but-last [xs] (cond (empty? (rest (rest xs))) xs :otherwise (recur (rest xs)))) (println (my-but-last '(a b c d))) (defn element-at [xs n] (cond (empty? xs) "failed" (= n 1) (first xs) :otherwise (recur (rest xs) (- n 1)))) (println (element-at '(a b c d e) 3)) (defn length [xs] (defn length2 [xs n] (cond (empty? xs) n :otherwise (recur (rest xs) (+ n 1)))) (length2 xs 0)) (println (length '(a b c d e))) (defn my-reverse [xs] (defn reverse2 [xs ys] (cond (empty? xs) ys ;:otherwise (recur (rest xs) (cons (first xs) ys)))) :otherwise (recur (rest xs) (conj ys (first xs))))) (reverse2 xs '())) (println (my-reverse '(a b c d e))) (defn palindrome? [xs] (= xs (my-reverse xs))) (println (palindrome? '(a b c d e))) (println (palindrome? '(a b c b a))) (defn my-flatten [xs] (cond (list? (first xs)) :otherwise 2)) (println (my-flatten '((a b) c (d (e)))))