Skip to content

Commit be7d3bb

Browse files
committed
Manual merge of working branch
2 parents 06df1be + 59fb171 commit be7d3bb

File tree

1 file changed

+34
-45
lines changed
  • for-clojure/problem-106/src/problem_106

1 file changed

+34
-45
lines changed

for-clojure/problem-106/src/problem_106/core.clj

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
(println "----------------")
1313
x#)))
1414

15-
;;; ___ _ _ _ __ __
16-
;;; | _ \_ _ ___| |__| |___ _ __ / |/ \ / /
15+
;;; ___ _ _ _ __ __
16+
;;; | _ \_ _ ___| |__| |___ _ __ / |/ \ / /
1717
;;; | _/ '_/ _ \ '_ \ / -_) ' \ | | () / _ \
1818
;;; |_| |_| \___/_.__/_\___|_|_|_| |_|\__/\___/
19-
19+
2020

2121
(def __ (letfn [(d [n] (* n 2)) ; double
2222
(h [n] (/ n 2)) ; halve
2323
(a [n] (+ n 2)) ; add
2424
(hop-count [n t m hops-so-far]
2525
(cond
2626
(= n t) hops-so-far ; end search
27-
(>= hops-so-far m) hops-so-far ; limit depth
27+
(>= hops-so-far m) hops-so-far ; limit depth
2828
:else
2929
(let [nh (inc hops-so-far) ; take a hop
3030
dh (hop-count (d n) t m nh)
3131
ah (hop-count (a n) t m nh)
3232
hh (when (even? n) (hop-count (h n) t m nh))]
3333
(cond
3434
(odd? n) (min dh ah)
35-
(even? n) (min dh ah hh)))))]
35+
(even? n) (min dh ah hh)))))]
3636
(fn [s t] (hop-count s t 10 1))))
3737

3838
(def __ #((fn r [n s]
@@ -48,7 +48,7 @@
4848
(cond
4949
(ts n) hops ; end search
5050
:else
51-
(hop-count n (set (concat ts (map d ts) (map a ts) (map h ts))) (inc hops))))]
51+
(hop-count n (set (concat ts (map d ts) (map a ts) (map h ts))) (inc hops))))]
5252
(fn [s t] (hop-count t #{s} 1))))
5353

5454
(println (map #(apply __ %) [[1 1] [3 12] [12 3] [5 9] [9 2] [9 12]]))
@@ -59,39 +59,8 @@
5959
(take 5 (range 5 java.lang.Integer/MAX_VALUE 2))
6060
(for [cand [2 3 4]] cand)
6161
(every? even? [4 2])
62-
63-
(def zork
64-
(fn [n] (take n (letfn [(primes []
65-
(lazy-seq
66-
(concat
67-
[2 3]
68-
(for [cand (range 5 java.lang.Integer/MAX_VALUE 2)
69-
:when (every? (fn [p] (not= 0 (mod cand p)))
70-
(take-while
71-
(fn [p] (< (* p p) cand))
72-
(primes)))
73-
]
74-
cand
75-
))))]
76-
(primes)
77-
))))
78-
79-
(def zork
80-
(fn [n] (take n (letfn [(primes []
81-
(lazy-seq
82-
(concat
83-
[2 3]
84-
(for [cand (range 5 java.lang.Integer/MAX_VALUE 2)
85-
:when (every? (fn [p] (not= 0 (mod cand p)))
86-
(take-while
87-
(fn [p] (< (* p p) cand))
88-
(primes)))
89-
]
90-
cand
91-
))))]
92-
(primes)
93-
))))
94-
62+
(range 5 100 2)
63+
(take 15 (iterate inc 2))
9564

9665
(def driver-table
9766
(pdump (map (partial zipmap [:chan :pl :driver-name :asin :prime :amount])
@@ -143,8 +112,8 @@
143112
(pdump (allocate (first pnls)
144113
(driver-spec :prod-cogs (first pnls))))
145114
(defn fact [n acc]
146-
(if
147-
(< n 2N)
115+
(if
116+
(< n 2N)
148117
acc
149118
(recur (dec n) (* acc n))))
150119

@@ -160,12 +129,32 @@
160129
primes
161130
))
162131
[2 3]
163-
(range 5N (fact 1000N 2)))
132+
(range 5N 1000N 2))
164133
)))
165134

166-
;; primes = [2, 3] ++ [ cand | cand <- [5, 7..],
135+
((fn [comb & hms]
136+
(reduce
137+
(fn [dest src]
138+
(into dest
139+
(reduce
140+
(fn [hm [k v]]
141+
(assoc hm k
142+
(let [curr (dest k)]
143+
(if curr (comb curr v) v))))
144+
{}
145+
src)))
146+
hms))
147+
*
148+
{:a 2, :b 3, :c 4},
149+
{:a 2},
150+
{:b 2},
151+
{:c 5}
152+
)
153+
154+
((fn [sent])
155+
"Have a nice day.")
156+
157+
;; primes = [2, 3] ++ [ cand | cand <- [5, 7..],
167158
;; all (\p -> notDvbl cand p)
168159
;; (takeWhile (\p -> p*p < cand) primes) ]
169160

170-
(defn -main [& args]
171-
(alter-var-root #'*read-eval* (constantly false)))

0 commit comments

Comments
 (0)