Created
June 20, 2012 05:53
-
-
Save JackDanger/2958344 to your computer and use it in GitHub Desktop.
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 characters
(ns palindrome | |
(:use clojure.test)) | |
(with-test | |
(defn is-palindrome? | |
"is true if the given argument is a palindrome" | |
[string] | |
(loop [string string] | |
(cond | |
(= \space (first string)) | |
(recur (rest string)) | |
(= \space (last string)) | |
(recur (butlast string)) | |
(< (count string) 2) | |
true | |
(= (first string) (last string)) | |
(recur (butlast (rest string))) | |
:else false))) | |
(is (= true (is-palindrome? "racecar"))) | |
(is (= true (is-palindrome? "a man a plan a canal panama"))) | |
(is (= false (is-palindrome? "this is not a palindrome"))) | |
(is (= true (is-palindrome? "hannah")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment