Skip to content
Browse files

Add some missing combinations.

  • Loading branch information...
1 parent 99ff354 commit 02abb71adabc79adce12021dcec4c887cef0ccf4 @fffej committed Feb 17, 2009
Showing with 9 additions and 2 deletions.
  1. +9 −2 countdown.clj
View
11 countdown.clj
@@ -12,7 +12,7 @@
(= + op) true
(= - op) (> a b)
(= * op) true
- (= / op) (= 0 (mod a b))))
+ (= / op) (= (mod a b) 0)))
(defstruct node :expression :value)
@@ -50,12 +50,19 @@
remd (drop 2 x)]
(mapcat make-expressions-helper (map (fn [x] (cons x remd)) exps)))))
+(defn drop-one
+ "All combinations of a lst without one element"
+ [lst]
+ (let [v (into [] lst) size (count v)]
+ (map (fn [x] (concat (subvec v 0 (dec x)) (subvec v x))) (range 1 (inc size)))))
+
+
(defn make-expressions [lst]
(if (nil? lst)
nil
(lazy-cat
(mapcat make-expressions-helper (permutations lst))
- (make-expressions (rest lst)))))
+ (mapcat make-expressions (drop-one lst)))))
(defn solve
"Solve the countdown problem"

0 comments on commit 02abb71

Please sign in to comment.
Something went wrong with that request. Please try again.