Created
March 11, 2012 22:50
-
-
Save anonymous/2018527 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
;; ariarule's solution to Digits and bases | |
;; https://4clojure.com/problem/137 | |
(fn convert-base | |
([n b] | |
(if (= n 0) '(0) | |
(let [p (reverse (take-while #(<= % n) (map #(Math/pow b %) (range))))] | |
(convert-base '() p n )))) | |
([l p r] | |
(if (= (count p) 1) | |
(reverse (conj l (int r))) | |
(convert-base (conj l (int (/ r (first p)))) (rest p) (rem r (first p)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment