Taxicab numbers: Difference between revisions
Content added Content deleted
Line 267: | Line 267: | ||
(if (and (= num-tried check-after) (enough? m n-to-generate)) ; check if we found enough taxi numbers |
(if (and (= num-tried check-after) (enough? m n-to-generate)) ; check if we found enough taxi numbers |
||
(sort-by first (into [] (filter #(> (count (second %)) 1) m))) ; sort the taxi numbers and this is the result |
(sort-by first (into [] (filter #(> (count (second %)) 1) m))) ; sort the taxi numbers and this is the result |
||
(if (= num-tried check-after) ; Check if we need to increase our |
(if (= num-tried check-after) ; Check if we need to increase our count between checking |
||
(recur (dict-inc m (first p)) (rest p) (inc num-tried) (* 2 check-after)) ; increased count between checking |
(recur (dict-inc m (first p)) (rest p) (inc num-tried) (* 2 check-after)) ; increased count between checking |
||
(recur (dict-inc m (first p)) (rest p) (inc num-tried) check-after))))) ; didn't increase |
(recur (dict-inc m (first p)) (rest p) (inc num-tried) check-after))))) ; didn't increase the count |
||
; Generate 1st 2006 taxi numbers |
; Generate 1st 2006 taxi numbers |