From 3736c832a786bf628dfc70bb5cdb95e3068ca864 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Tue, 8 Sep 2020 14:38:24 -0700 Subject: Task 1: improve performance Take Fibonacci Numbers as long as they're less than the sum target (we can eliminate the case of the Fibonacci Number being equal to the sum target because 0 is disallowed for this challenge). --- challenge-077/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-077/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj b/challenge-077/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj index 4ab609b3d8..4d5d0e1375 100644 --- a/challenge-077/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj +++ b/challenge-077/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj @@ -20,7 +20,7 @@ (defn fibo-sum "Find all combinations of Fibonacci Numbers that sum to n, returning nil if none are found." [n] - (let [fibs (drop 2 (take n (fibo-lazy-seq))) + (let [fibs (drop 2 (take-while #(< % n) (fibo-lazy-seq))) results (->> fibs combo/subsets (drop 1) ; remove the empty subset, which is always first -- cgit