|
12 | 12 | (println "----------------") |
13 | 13 | x#))) |
14 | 14 |
|
15 | | -;;; ___ _ _ _ __ __ |
16 | | -;;; | _ \_ _ ___| |__| |___ _ __ / |/ \ / / |
| 15 | +;;; ___ _ _ _ __ __ |
| 16 | +;;; | _ \_ _ ___| |__| |___ _ __ / |/ \ / / |
17 | 17 | ;;; | _/ '_/ _ \ '_ \ / -_) ' \ | | () / _ \ |
18 | 18 | ;;; |_| |_| \___/_.__/_\___|_|_|_| |_|\__/\___/ |
19 | | - |
| 19 | + |
20 | 20 |
|
21 | 21 | (def __ (letfn [(d [n] (* n 2)) ; double |
22 | 22 | (h [n] (/ n 2)) ; halve |
23 | 23 | (a [n] (+ n 2)) ; add |
24 | 24 | (hop-count [n t m hops-so-far] |
25 | 25 | (cond |
26 | 26 | (= 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 |
28 | 28 | :else |
29 | 29 | (let [nh (inc hops-so-far) ; take a hop |
30 | 30 | dh (hop-count (d n) t m nh) |
31 | 31 | ah (hop-count (a n) t m nh) |
32 | 32 | hh (when (even? n) (hop-count (h n) t m nh))] |
33 | 33 | (cond |
34 | 34 | (odd? n) (min dh ah) |
35 | | - (even? n) (min dh ah hh)))))] |
| 35 | + (even? n) (min dh ah hh)))))] |
36 | 36 | (fn [s t] (hop-count s t 10 1)))) |
37 | 37 |
|
38 | 38 | (def __ #((fn r [n s] |
|
48 | 48 | (cond |
49 | 49 | (ts n) hops ; end search |
50 | 50 | :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))))] |
52 | 52 | (fn [s t] (hop-count t #{s} 1)))) |
53 | 53 |
|
54 | 54 | (println (map #(apply __ %) [[1 1] [3 12] [12 3] [5 9] [9 2] [9 12]])) |
|
59 | 59 | (take 5 (range 5 java.lang.Integer/MAX_VALUE 2)) |
60 | 60 | (for [cand [2 3 4]] cand) |
61 | 61 | (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)) |
95 | 64 |
|
96 | 65 | (def driver-table |
97 | 66 | (pdump (map (partial zipmap [:chan :pl :driver-name :asin :prime :amount]) |
|
143 | 112 | (pdump (allocate (first pnls) |
144 | 113 | (driver-spec :prod-cogs (first pnls)))) |
145 | 114 | (defn fact [n acc] |
146 | | - (if |
147 | | - (< n 2N) |
| 115 | + (if |
| 116 | + (< n 2N) |
148 | 117 | acc |
149 | 118 | (recur (dec n) (* acc n)))) |
150 | 119 |
|
|
160 | 129 | primes |
161 | 130 | )) |
162 | 131 | [2 3] |
163 | | - (range 5N (fact 1000N 2))) |
| 132 | + (range 5N 1000N 2)) |
164 | 133 | ))) |
165 | 134 |
|
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..], |
167 | 158 | ;; all (\p -> notDvbl cand p) |
168 | 159 | ;; (takeWhile (\p -> p*p < cand) primes) ] |
169 | 160 |
|
170 | | -(defn -main [& args] |
171 | | - (alter-var-root #'*read-eval* (constantly false))) |
0 commit comments