loading...

re: Daily Challenge #231 - Perfect Powers VIEW POST

FULL DISCUSSION
 

Not necessarily the best approach, but this works in Clojure

(defn pp? [x]
  (let [logx (Math/log x)
        range-to #(range 2 (inc %))
        power? (fn [m]
                 (when-let [k (some
                                #(if (= x (long (Math/pow m %))) %)
                                (range-to (/ logx (Math/log m))))]
                   [m k]))]
    (some power? (range-to (Math/sqrt x)))))
code of conduct - report abuse