4clojure 题解 Palindrome Detector

作者: admin 日期: 2017-12-27 16:01:43 人气: - 评论: 0

经典的回文判断问题

Write a function which returns true if the given sequence is a palindrome.

Hint: "racecar" does not equal '(\r \a \c \e \c \a \r)

test not run
(false? (__ '(1 2 3 4 5)))
test not run
(true? (__ "racecar"))
test not run
(true? (__ [:foo :bar :foo]))
test not run
(true? (__ '(1 1 3 3 1 1)))
test not run
(false? (__ '(:a :b :c)))














(fn [all]
(let [rev (reverse all)
len (count all)
flen (inc (int (/ len 2)))]
(every? true? (map (fn [x]
(= (nth rev x)
(nth all x))
) (range flen)))
)
)


相关内容

发表评论
更多 网友评论0 条评论)
暂无评论

Copyright © 2012-2014 我的代码板 Inc. 保留所有权利。

页面耗时0.0247秒, 内存占用1.83 MB, 访问数据库13次

闽ICP备15009223号-1