Last active
August 29, 2015 13:56
-
-
Save mishadoff/9089925 to your computer and use it in GitHub Desktop.
Revisions
-
mishadoff revised this gist
Feb 19, 2014 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,4 +25,16 @@ ;; 707106780 ;; 49 ;; "Elapsed time: 4.398956 msecs" ;; :ok (defn solve-file [in out] (->> (slurp in) (re-seq #"\d+") (map bigint) (rest) (partition 2 2) (map-indexed #(vec [(inc %1) (apply solve %2)])) (map #(format "Case #%d: %d" (first %) (last %))) (interpose "\n") (apply str) (spit out))) -
mishadoff created this gist
Feb 19, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ (defn solve [r t] "r - initial radius, t - mls of paint" (letfn [(nrings [n] (+' (*' 2 n n) (-' n) (*' 2 r n))) (binary [[a b]] (cond (or (= a b) (= (inc a) b)) a :else (let [avg (quot (+' a b) 2) pnt (nrings avg)] (if (<= pnt t) (recur [avg b]) (recur [a avg])))))] (binary [0 1000000000000000000]))) ;; bulllseye> (time (do (println (solve 1 9)) ;; (println (solve 1 10)) ;; (println (solve 3 40)) ;; (println (solve 1 1000000000000000000)) ;; (println (solve 10000000000000000 1000000000000000000)) ;; :ok)) ;; 1 ;; 2 ;; 3 ;; 707106780 ;; 49 ;; "Elapsed time: 4.398956 msecs" ;; :ok