aboutsummaryrefslogtreecommitdiff
path: root/challenge-077
diff options
context:
space:
mode:
authorTyler Wardhaugh <tyler.wardhaugh@gmail.com>2020-09-08 14:38:24 -0700
committerTyler Wardhaugh <tyler.wardhaugh@gmail.com>2020-09-08 14:41:04 -0700
commit3736c832a786bf628dfc70bb5cdb95e3068ca864 (patch)
treed926b8ded511e3a8e45d4483f5a068f0abe361ce /challenge-077
parentd6124e1dd1e2f11c081daf991b6000d5a1666917 (diff)
downloadperlweeklychallenge-club-3736c832a786bf628dfc70bb5cdb95e3068ca864.tar.gz
perlweeklychallenge-club-3736c832a786bf628dfc70bb5cdb95e3068ca864.tar.bz2
perlweeklychallenge-club-3736c832a786bf628dfc70bb5cdb95e3068ca864.zip
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).
Diffstat (limited to 'challenge-077')
-rw-r--r--challenge-077/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj2
1 files changed, 1 insertions, 1 deletions
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