Skip to content

Instantly share code, notes, and snippets.

@brendanmaguire
Last active January 26, 2018 09:00
Show Gist options
  • Save brendanmaguire/f515eabc6c0f436db1a82508b03ee522 to your computer and use it in GitHub Desktop.
Save brendanmaguire/f515eabc6c0f436db1a82508b03ee522 to your computer and use it in GitHub Desktop.
Functional Kata Meetup - Clojure solution
; Solution to https://github.com/danielytics/sherlock-and-array/
; Functional Kata meetup https://www.meetup.com/FunctionalKubs/events/246876977/
(defn solve
[s]
(
let [total (reduce + s)]
(defn balanced [arr, accum]
(if (<= (count arr) 1)
false
(
let [[first second & rest] arr]
(
let [new_accum (+ accum first)]
(if (= (- total second) (* new_accum 2))
true
(balanced (cons second rest) new_accum)
)
)
)
)
)
(if (balanced s 0)
(println "YES")
(println "NO")
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment