Skip to content

Instantly share code, notes, and snippets.

@JackDanger
Created June 20, 2012 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackDanger/2958344 to your computer and use it in GitHub Desktop.
Save JackDanger/2958344 to your computer and use it in GitHub Desktop.
(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