tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,12 @@
(defn rot-13 [c]
(let [i (int c)]
(cond
(or (and (>= i (int \a)) (<= i (int \m)))
(and (>= i (int \A)) (<= i (int \M))))
(char (+ i 13))
(or (and (>= i (int \n)) (<= i (int \z)))
(and (>= i (int \N)) (<= i (int \Z))))
(char (- i 13))
:else c)))
(apply str (map rot-13 "abcxyzABCXYZ")) ;; output "nopklmNOPKLM"

View file

@ -0,0 +1,7 @@
(let [A (into #{} "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
A-map (zipmap A (take 52 (drop 26 (cycle A))))]
(defn rot13[in-str]
(reduce str (map #(if (A %1) (A-map %1) %1) in-str))))
(rot13 "The Quick Brown Fox Jumped Over The Lazy Dog!") ;; produces "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt!"