Skip to content

Instantly share code, notes, and snippets.

@mwmitchell
Created February 9, 2012 01:48
Show Gist options
  • Save mwmitchell/1776413 to your computer and use it in GitHub Desktop.
Save mwmitchell/1776413 to your computer and use it in GitHub Desktop.
division expansion
(defn de [x n]
(loop [x x nr (vec (range 1 (+ n 1))) z []]
(let [q (quot x (last nr))]
(if-let [xx (not-empty (subvec nr 0 (- (count nr) 1)))]
(recur (- x q) xx (concat z [q]))
(concat z [q])))))
(de 8 2)
(de 7 3)
(de 7 2)
(de 10 5)
(de 10 2)
(de 10 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment