Skip to content

Instantly share code, notes, and snippets.

@miner
Created February 23, 2015 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miner/6b45c53e3a12367260a9 to your computer and use it in GitHub Desktop.
Save miner/6b45c53e3a12367260a9 to your computer and use it in GitHub Desktop.
(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