Last active
December 22, 2015 06:29
-
-
Save sztamas/6431618 to your computer and use it in GitHub Desktop.
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
| (defn product | |
| ([] []) | |
| ([xs] (if (empty? xs) [] (seq xs))) | |
| ([xs & rest] | |
| (for [x xs p (apply product rest)] (flatten (list x p))))) | |
| (defn endless-product [xs] | |
| (let [repeat-xs (map #(repeat % xs) (drop 1 (range)))] | |
| (apply concat (map #(apply product %) repeat-xs)))) | |
| (comment | |
| (take 13 (endless-product "abc")) | |
| '(\a \b \c (\a \a) (\a \b) (\a \c) (\b \a) (\b \b) (\b \c) (\c \a) (\c \b) (\c \c) (\a \a \a)) | |
| (take 2 (drop 10000 (endless-product "abc"))) | |
| '((\a \a \a \a \b \c \c \c \b) (\a \a \a \a \b \c \c \c \c)) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment