Commits

Ivan Andrus committed 87ca158

First step towards using clojure's pipeline macro

Comments (0)

Files changed (1)

           `(~(symbol (name (first body))) ~@(pieces 0))
         `(~(symbol (name (first body))) ~@(pieces 0) (pipeline ~@(pieces 1)))))
     `(do ~@body)))
+
+;; This one is from http://richhickey.github.com/clojure/clojure.core-api.html
+;; I'm not sure why I don't have it
+(defmacro ->>
+  "Threads the expr through the forms. Inserts x as the
+  last item in the first form, making a list of it if it is not a
+  list already. If there are more forms, inserts the first form as the
+  last item in second form, etc."
+  ([x form] (if (seq? form)
+              (with-meta `(~(first form) ~@(next form)  ~x) (meta form))
+              (list form x)))
+  ([x form & more] `(->> (->> ~x ~form) ~@more)))
+
+
 ;}}}
 
 
     :map #(list (totient %) %)
     (range 2 n)))
 
+(defn min-permuted-totient-quotient [n]
+  (->>
+    (range 2 n)
+    (map #(list (totient %) %))
+    (filter #(= (sort (to-digits (first %)))
+                (sort (to-digits (frest %)))))
+    (map #(list (/ (frest %) (first %)) (frest %)))
+    (reduce min-first)
+    frest
+    ))
+
+;; (min-permuted-totient-quotient 10000)
+
 ;; (time (min-permuted-totient-quotient 10000000))
 ;; "Elapsed time: 513006.925 msecs"
 ;; 8319823
 ;; memoize
 ;; (comp f g h) -> f(g(h(*)))
 
+
+
+;; This is perhaps a similar problem.
+
+;; http://www.cs.umd.edu/~gasarch/BLOGPAPERS/17x17almost.txt
+;; http://bit-player.org/2009/the-17x17-challenge
+
+;; 00000111122223333
+;; 01111122223333000
+;; 02222133320003111
+;; 03333100021113222
+;; 10123212332300301
+;; 11032221033210032
+;; 12301230130120123
+;; 13210203231030210
+;; 20231313002011312
+;; 21320320303101021
+;; 22013331200231130
+;; 23102302101321203
+;; 30312010212132320
+;; 31203023113022013
+;; 32130032010312102
+;; 33021001311202231
+;; 0123+012301230123
+
+;; The + is the point that is not colored. I got this grid by trying to add a
+;; row to a 4-coloring of a 16x17 grid.
+
+
+
+
+;; http://clojars.org/