Last active
January 26, 2018 09:00
-
-
Save brendanmaguire/f515eabc6c0f436db1a82508b03ee522 to your computer and use it in GitHub Desktop.
Functional Kata Meetup - Clojure solution
This file contains 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 characters
; 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