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