Skip to content

Instantly share code, notes, and snippets.

@Licenser
Created June 23, 2010 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Licenser/449701 to your computer and use it in GitHub Desktop.
Save Licenser/449701 to your computer and use it in GitHub Desktop.
(ns fannkuchen2
(use [clojure.contrib.combinatorics :only [lex-permutations]])
(:gen-class))
(set! *warn-on-reflection* true)
(defn fankuchen [m]
(loop [[f & _ :as m] m c 0]
(if (= f 1 )
c
(recur
(concat
(reverse (take f m))
(drop f m))
(inc c)))))
(defn -main [a]
(let [n (Integer/parseInt a)]
(println
(str "Pfannkuchen(" n ") =")
(apply max (map fankuchen (lex-permutations (range 1 (inc n))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment