Skip to content

Instantly share code, notes, and snippets.

@noncom
Created May 15, 2017 07:37
Show Gist options
  • Save noncom/e2866837dcded29fdffe4958273cd44e to your computer and use it in GitHub Desktop.
Save noncom/e2866837dcded29fdffe4958273cd44e to your computer and use it in GitHub Desktop.
(let [fs [+ - *]
cbd [c b d]
m (x a b c d)]
(for [f1 fs f2 fs f3 fs,
o-1 cbd o-2 cbd o-3 cbd]
(let [res (f1 (f2 (f3 m o-1) o-2) o-3)]
[(make res a) [f1 f2 f3] [o-1 o-2 o-3] res])))
@christoph-frick
Copy link

(Hopefully) generic version using https://github.com/clojure/math.combinatorics

(require '[clojure.math.combinatorics :as combo :refer [permutations]])
(let [fs [+ - *]
      cbd [1 2 3] 
      init 0]
  (for [f (permutations fs)
        args (permutations cbd)]
    (reduce  
      (fn [r [f x]] (f r x))
      init
      (map vector fs args))))

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