Created
June 20, 2015 08:08
-
-
Save ynonp/f54b6bfb5732c0001628 to your computer and use it in GitHub Desktop.
clojure demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns clojure-noob.core | |
(:gen-class)) | |
(require 'digest) | |
(defn exp [x n] | |
(reduce * (repeat n x))) | |
(defn char_at [ab i d] | |
(ab (rem | |
(int (/ i (exp (count ab) d))) | |
(int (count ab)) | |
))) | |
(defn gen-word-at [ab len] | |
(fn [i] | |
(clojure.string/join | |
(map | |
(fn [d] (char_at ab i d)) | |
(range len)) | |
))) | |
(defn pair-at [word-at i] | |
(def word (word-at i)) | |
(def md5 (digest/md5 word)) | |
{ md5 word }) | |
(defn -main | |
[& args] | |
(println "start") | |
(def ab (vec "0123456789abcdefghijklmnopqrstuwvxyz")) | |
(def len 4) | |
(def total (exp (count ab) len)) | |
(def trace 100000) | |
(def word-at (gen-word-at ab len)) | |
(def my-pair-at (partial pair-at word-at)) | |
(def pairs (reduce merge (map my-pair-at (range total)))) | |
(println (get pairs "657f8b8da628ef83cf69101b6817150a")) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment