update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
21
Task/Semordnilap/Clojure/semordnilap.clj
Normal file
21
Task/Semordnilap/Clojure/semordnilap.clj
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
(use 'clojure.java.io)
|
||||
(require '[clojure.string :as string])
|
||||
|
||||
(def dict-file (or (first *command-line-args*) "unixdict.txt"))
|
||||
|
||||
(def dict (set (line-seq (reader dict-file))))
|
||||
|
||||
(defn semordnilap? [word]
|
||||
(let [rev (string/reverse word)]
|
||||
(and (not (= word rev)) (dict rev))))
|
||||
|
||||
(def semordnilaps
|
||||
(filter (fn [[x y]] (<= (compare x y) 0))
|
||||
(map (fn [word] [word (string/reverse word)])
|
||||
(filter semordnilap? dict))))
|
||||
|
||||
(printf "There are %d semordnilaps in %s. Here are 5:\n"
|
||||
(count semordnilaps)
|
||||
dict-file)
|
||||
|
||||
(dorun (map println (sort (take 5 (shuffle semordnilaps)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue