Created
February 23, 2015 18:26
-
-
Save miner/6b45c53e3a12367260a9 to your computer and use it in GitHub Desktop.
This file contains 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 miner.lucky | |
(:require [clojure.data.avl :as avl])) | |
;; http://en.wikipedia.org/wiki/Lucky_number | |
(defn lucky-avl | |
([max] (lucky-avl 1 (apply avl/sorted-set (range 1 max 2)))) | |
([i avl] | |
(let [n (nth avl i nil)] | |
(if (and n (<= n (count avl))) | |
(recur (inc i) (reduce (fn [sss m] (disj sss (nth avl m))) | |
avl | |
(range (dec n) (count avl) n))) | |
(sequence avl))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment