Skip to content

Instantly share code, notes, and snippets.

@danneu
Created April 27, 2013 22:41
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 danneu/820c024cb62859371f4c to your computer and use it in GitHub Desktop.
Save danneu/820c024cb62859371f4c to your computer and use it in GitHub Desktop.
(ns tnt.multi-miner
(:require [clojure.string :refer [join]]
[tnt.crypto :refer :all])
(:gen-class))
(def ascii (->> (range 97 123) (concat (range 65 91)) (map char) (concat (range 10))))
(def difficulty 7)
(def upper-bound 1000000000)
(def prefix (join (repeat difficulty "0")))
(def solution (agent nil))
(defn watcher [key ref old new]
(println "Solution found: " new)
(spit "solutions.txt" (str new \newline) :append true))
(add-watch solution "key" watcher)
(defn gen-seed [] (join (take 5 (shuffle ascii))))
(defn work [seed]
(loop [n 0]
(when (= n upper-bound) nil)
(let [guess (str seed n)]
(if (.startsWith (sha512 guess) prefix)
(do (send solution (fn [_] guess)) guess)
(recur (inc n))))))
(defn -main [& args] (pmap work (repeatedly gen-seed)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment