Skip to content

Instantly share code, notes, and snippets.

@Ivana-
Created January 5, 2019 12:44
Show Gist options
  • Save Ivana-/97ed107fb81dc1f8f00baf16e3e85cdc to your computer and use it in GitHub Desktop.
Save Ivana-/97ed107fb81dc1f8f00baf16e3e85cdc to your computer and use it in GitHub Desktop.
webinar 2 Clojure
(do
(def ones
(lazy-seq (cons 1 ones)))
(prn (take 10 ones))
(defn intfrom [n]
(lazy-seq (cons n (intfrom (+ 1 n)))))
(prn (take 10 (intfrom 1)))
(print "\nчисла Фибоначчи:\n")
(def fibs (cons 0
(lazy-seq (cons 1 (map + (rest fibs) fibs)))))
(prn (take 50 fibs))
(print "\nчисла Хэмминга:\n")
(defn s-merge [a b]
(lazy-seq
(let [ha (first a) hb (first b)]
(cond
(< ha hb) (cons ha (s-merge (rest a) b))
(> ha hb) (cons hb (s-merge a (rest b)))
:else (cons ha (s-merge (rest a) (rest b)))))))
(def hamm
(lazy-seq
(->> (map #(*' 2 %) hamm)
(s-merge (map #(*' 3 %) hamm))
(s-merge (map #(*' 5 %) hamm))
(cons 1))))
(prn (take 50 hamm))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment