Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Checked in work in progress for 96, 111, 204.

  • Loading branch information...
commit 38d84e8ce6629757857612c0d251b5b218df6c11 1 parent abc3b06
@darrenaustin authored
View
4 .gitignore
@@ -2,4 +2,6 @@ pom.xml
*jar
lib
classes
-*DS_Store
+*DS_Store
+.idea
+*.iml
View
34 src/dma/euler/p096.clj
@@ -0,0 +1,34 @@
+(ns dma.euler.p096)
+
+(defn cross [A B f]
+ (for [a A b B] (str a b)))
+
+(def digits "123456789")
+(def rows "ABCDEFGHI")
+(def cols digits)
+(def squares (cross rows cols))
+
+;(def cols (for [y ds] (for [x ds] [x y])))
+;(def rows (for [y ds] (for [x ds] [y x])))
+;(def boxes (for [by (range 3) bx (range 3)]
+; (for [y (range 3) x (range 3)]
+; [(+ (* bx 3) x) (+ (* by 3) y)])))
+;(def groups (concat cols rows boxes))
+
+(defn read-puzzles []
+ (map (fn [board-data]
+ (vec (map #(vec (replace {\0 nil} %)) (rest board-data))))
+ (partition 10 (.split (slurp "data/sudoku.txt") "\n"))))
+
+(defn print-puzzle [puzzle]
+ (let [row-divider "+-------+-------+-------+"]
+ (doseq [y (range 9)]
+ (when (zero? (rem y 3))
+ (println row-divider))
+ (println (apply format "| %s %s %s | %s %s %s | %s %s %s |"
+ (map #(or % \space) (puzzle y)))))
+ (println row-divider)))
+
+(defn solution {:answer 24702} []
+ (let [puzzles (read-puzzles)]
+ (print-puzzle (first puzzles))))
View
30 src/dma/euler/p111.clj
@@ -0,0 +1,30 @@
+(ns dma.euler.p111
+ (:use dma.euler.numeric dma.euler.primes))
+
+(defn n-digit-primes [n]
+ (let [max (exp 10 n)
+ min (exp 10 (dec n))]
+ (take-between min max (primes))))
+
+(defn repeating-digits [n]
+ (let [repeats (group-by identity (digits n))]
+ (reduce (fn [m k]
+ (let [num (count (m k))]
+ (if (< 1 num)
+ (assoc m k num)
+ (dissoc m k))))
+ repeats (keys repeats))))
+
+(defn update-max-digit-map [m n]
+ (let [repeat-digits (repeating-digits n)]
+ (reduce (fn [m [digit repeats]]
+ (let [max-repeats (get-in m [digit :max] 0)]
+ (cond (< repeats max-repeats) m
+ (= repeats max-repeats) (update-in m [digit :sum] + n)
+ :else (assoc m digit {:max repeats :sum n}))))
+ m repeat-digits)))
+
+(defn solution {:answer nil} []
+ (let [max-digit-map (reduce update-max-digit-map {} (n-digit-primes 10))]
+ (sum (map #(get-in max-digit-map [% :sum]) (range 10)))))
+
View
9 src/dma/euler/p204.clj
@@ -0,0 +1,9 @@
+(ns dma.euler.p204
+ (:use [dma.euler numeric primes]))
+
+(defn hamming? [n max-prime-factor]
+ (every? #(<= % max-prime-factor) (prime-factors n)))
+
+(defn solution {:answer nil} []
+ (count
+ (take-while-< (exp 10 5) (filter #(hamming? % 5) (natural-nums)))))
Please sign in to comment.
Something went wrong with that request. Please try again.