Last active
August 29, 2015 14:18
-
-
Save yurrriq/c7ff37c67dc6cf139af9 to your computer and use it in GitHub Desktop.
4Clojure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns me.ericb.fourclojure.one-eighteen) | |
(defn map' | |
"Given a function f and an input sequence s, | |
return a lazy sequence of (f x) for each element x in s." | |
{:see-also [["http://www.4clojure.com/problem/118" | |
"118. Re-implement Map"]]} | |
[f s] | |
(lazy-seq | |
(when (seq s) | |
(cons (f (first s)) | |
(map' f (rest s)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns me.ericb.fourclojure.one-hundred) | |
(defn gcd [a b] | |
(loop [k (max a b), m (min a b)] | |
(if (zero? m) k (recur m (mod k m))))) | |
(defn lcm [& args] | |
(loop [coll args] | |
(if-not (second coll) | |
(first coll) | |
(->> (partition 2 1 coll) | |
(map #(/ (apply * %) (apply gcd %))) | |
(recur))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns me.ericb.fourclojure.one-twenty) | |
(defn square [x] (* x x)) | |
(defn sum [coll] (reduce + coll)) | |
(defn char->digit [c] (Character/digit c 10)) | |
(defn squared-digits [x] (map (comp square char->digit) (str x))) | |
(defn lt-sum-squared-digits? [x] (< x (sum (squared-digits x)))) | |
(defn one-twenty [coll] (count (filter lt-sum-squared-digits? coll))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment