Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,21 +1,24 @@
(use 'clojure.java.io)
(require '[clojure.string :as string])
(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-file
(or (first *command-line-args*) "unixdict.txt"))
(def dict (set (line-seq (reader dict-file))))
(def dict (-> dict-file io/reader line-seq set))
(defn semordnilap? [word]
(let [rev (string/reverse word)]
(and (not (= word rev)) (dict rev))))
(let [rev (str/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))))
(->> 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 (map println (sort (take 5 (shuffle semordnilaps)))))
(dorun (->> semordnilaps shuffle (take 5) sort (map println)))