Created
February 16, 2010 13:26
-
-
Save francoisdevlin/305521 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
(import [java.math BigInteger]) | |
(defn conway-PM [] | |
(let [factors [17/91 78/85 19/51 23/38 29/33 77/29 95/23 | |
77/19 1/17 11/13 13/11 15/14 15/2 55/1] | |
big-int (fn [n];"makes a bigint from int, if needed" | |
(if (instance? BigInteger n) | |
n (BigInteger/valueOf n))) | |
special-log (fn [n]; base 2 log of n iff n = 2^m, else nil | |
(let [bn (big-int n)] | |
(if (= (.bitCount #^BigInteger bn) 1) | |
(- (.bitLength #^BigInteger bn) 1)))) | |
step ;"Multiplies with the first factor to give an integer." | |
(fn [n, unused-factors] | |
(let [factor (first unused-factors) | |
rest-factors (rest unused-factors) | |
dummy (* n factor)] | |
(if (integer? dummy) | |
dummy | |
(recur n rest-factors))))] | |
(iterate #(step % factors) 2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment