Skip to content

Instantly share code, notes, and snippets.

@mishadoff
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save mishadoff/9089925 to your computer and use it in GitHub Desktop.

Select an option

Save mishadoff/9089925 to your computer and use it in GitHub Desktop.

Revisions

  1. mishadoff revised this gist Feb 19, 2014. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion gistfile1.clj
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,16 @@
    ;; 707106780
    ;; 49
    ;; "Elapsed time: 4.398956 msecs"
    ;; :ok
    ;; :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)))
  2. mishadoff created this gist Feb 19, 2014.
    28 changes: 28 additions & 0 deletions gistfile1.clj
    Original 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