Skip to content

Instantly share code, notes, and snippets.

@BrunoBonacci
Created May 16, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrunoBonacci/cb13fc05bd720652eb17 to your computer and use it in GitHub Desktop.
Save BrunoBonacci/cb13fc05bd720652eb17 to your computer and use it in GitHub Desktop.
Crypto Square problem
(defn crypto-square [s]
(->> (re-seq #"\w+" s)
(map clojure.string/lower-case)
(apply str)
(#(let [size (int (Math/ceil (Math/sqrt (count %))))]
(partition size size (repeat " ") %)))
(apply map vector)
(map (partial apply str))
(clojure.string/join "\n")))
(println (crypto-square "If man was meant to stay on the ground god would have given us roots"))
;; imtgdvs
;; fearwer
;; mayoogo
;; anouuio
;; ntnnlvt
;; wttddes
;; aohghn
;; sseoau
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment