Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
(defn filter-collecting [predicate collector & lists]
(lazy-seq
(loop [lists lists out []]
(if (empty? (first lists))
(reverse out)
(let [heads (map first lists)]
(if (apply predicate heads)
(recur (map rest lists) (cons (apply collector heads) out))
(recur (map rest lists) out)))))))
(defn filter-collecting [predicate collector & lists]
(lazy-seq
(loop [lists lists out []]
(if (empty? (first lists))
(reverse out)
(let [heads (map first lists)]
(if (apply predicate heads)
(recur (map rest lists) (cons (apply collector heads) out))
(recur (map rest lists) out)))))))
(defn filter-collecting [predicate collector & lists]
(lazy-seq
(loop [lists lists out []]
(if (empty? (first lists))
(reverse out)
(let [heads (map first lists)]
(if (apply predicate heads)
(recur (map rest lists) (cons (apply collector heads) out))
(recur (map rest lists) out)))))))
(defn filter-collecting [predicate collector & lists]
(lazy-seq
(loop [lists lists out []]
(if (empty? (first lists))
(reverse out)
(let [heads (map first lists)]
(if (apply predicate heads)
(recur (map rest lists) (cons (apply collector heads) out))
(recur (map rest lists) out)))))))
(defn filter-collecting [predicate collector & lists]
(lazy-seq
(loop [lists lists out []]
(if (empty? (first lists))
(reverse out)
(let [heads (map first lists)]
(if (apply predicate heads)
(recur (map rest lists) (cons (apply collector heads) out))
(recur (map rest lists) out)))))))
;; largest prime factor
(defn lpf
"Takes a number n and a starting number d > 1
and calculates the largest prime factor of n
starting at number d.
usage: (lpf 364362978 2) => 8675309"
[n d]
(if (> d n)
;; largest prime factor
(defn lpf
"Takes a number n and a starting number d > 1
and calculates the largest prime factor of n
starting at number d.
usage: (lpf 364362978 2) => 8675309"
[n d]
(if (> d n)
;; largest prime factor
(defn lpf
"Takes a number n and a starting number d > 1
and calculates the largest prime factor of n
starting at number d.
usage: (lpf 364362978 2) => 8675309"
[n d]
(if (> d n)
;; largest prime factor
(defn lpf
"Takes a number n and a starting number d > 1
and calculates the largest prime factor of n
starting at number d.
usage: (lpf 364362978 2) => 8675309"
[n d]
(if (> d n)
;; largest prime factor
(defn lpf
"Takes a number n and a starting number d > 1
and calculates the largest prime factor of n
starting at number d.
usage: (lpf 364362978 2) => 8675309"
[n d]
(if (> d n)