Skip to content

Instantly share code, notes, and snippets.

@dfuenzalida
Last active December 16, 2019 03:35
Show Gist options
  • Save dfuenzalida/42cb257e2a9a93e20859fa53e8f43f56 to your computer and use it in GitHub Desktop.
Save dfuenzalida/42cb257e2a9a93e20859fa53e8f43f56 to your computer and use it in GitHub Desktop.
Desafío Primes Crypto
(ns programando.core)
(def primes [2 3 5 7 11 13 17 19 23 29])
(defn index-to-letter [i]
(char (+ i (int \a) -1)))
(defn factors [n fs ps]
(if (> n 1)
(let [p (first ps)]
(if (zero? (mod n p))
(recur (quot n p) (merge-with + fs {p 1}) ps)
(recur n fs (rest ps))))
fs))
(defn decrypt [n]
(->> (factors n (sorted-map) primes) (map (comp index-to-letter second)) (reduce str)))
(defn -main []
(dorun
(map (comp println decrypt)
[40233680140239064308212773133312764943748000000000000000000
45087592346382488832366326449069283133412065695070241853706487031250000
8679608265978819446726615827418826755071534791227586000000000000000
27914797455418138364383974433340682351379394531250000
1059246326897806934956526951511712774422030066044771506277207862450866815727414664067933302815246198122035444843750
])))
;; (-main)
;; Salida:
;; turing
;; dijstra
;; programa
;; desafio
;; algoritmo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment