-
-
Save danneu/820c024cb62859371f4c to your computer and use it in GitHub Desktop.
This file contains 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 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