Skip to content

Instantly share code, notes, and snippets.

@hikoz
Created May 29, 2015 05:53
Show Gist options
  • Save hikoz/a1331464559b744b4668 to your computer and use it in GitHub Desktop.
Save hikoz/a1331464559b744b4668 to your computer and use it in GitHub Desktop.
(->>
(let [[h & t] (range 1 10)]
(reduce
(fn [l h]
(mapcat (fn [[a b s]]
[[(conj a b) h (str s " + " h)]
[(conj a b) (- h) (str s " - " h)]
[a (bigint (str b h)) (str s h)]])
l))
[[[] h h]]
t))
(filter #(= (apply + (second %) (first %)) 100))
(map #(nth % 2)))
@hikoz
Copy link
Author

hikoz commented May 29, 2015

for

(let [[h & l] (range 1 10)
      r (loop [r [[[] h h]]
               [h & t] l]
          (if h
            (recur
              (mapcat (fn [[a b s]]
                        [[(conj a b) h (str s " + " h)]
                         [(conj a b) (- h) (str s " - " h)]
                         [a (bigint (str b h)) (str s h)]])
                      r)
              t)
            r))]
  (for [[a b c] r :when (= (apply + b a) 100)] c))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment