clojure-greece 2017-12-01

ξεκινησε το advent

η πρωτη ηταν ευκολη αλλα ωραιο να τη λυνεις με clj

#adventofcode 🙂

ωραια φαση με τα inline tests @orestis

εγω το προσεγγισα ετσι

@greenonion

(as-> "91212129" $
  (mapv #(Character/getNumericValue %) $)
  (conj $ (first $))
  (partition 2 1 $)
  (remove #(apply not= %) $)
  (map first $)
  (apply + $))

gia to 1o star toulaxiston

Ωραίο κι αυτό

Κανονικά θέλει transducers όμως :D

kai ego tora to ekana plaka eixe, to ekana me alli logiki me reduce kai indexes 😛

(defn captcha-solver
  ([s] (captcha-solver s 1))
  ([s step]
   (let [cycled (cycle s)]
     (reduce (fn [acc [i current]]
               (let [next (nth cycled (+ i step))]
                 (if (= next current)
                   (+ acc (Character/getNumericValue current))
                   acc))) 0 (keep-indexed vector s)))))