Oh man,
ich hab ein weiteres Ergebnis in den Raum zu werfen, dass sich von den anderen Unterscheidet.
Habe es mit Clojure mit Hilfe von core.logic gecoded. Core.logic hat mich immer schon interessiert, da tat so ein Anwendungsfall ganz gut.
(ns pyramides.core
(:use [clojure.core.logic])
(:require [clojure.core.logic.fd :as fd]))
(defn count-number-of-diff-numbers [coll]
(count (set coll)))
(defn all-possibilities []
(run* [a b c d]
(fd/in a b c d (fd/interval 1 5))
(fd/<= b c)
(fd/<= b d)))
(defn map-by-number-of-colors [coll]
(map (fn [x] [(count-number-of-diff-numbers x) x]) coll))
Die verschiedenen Farben sind als Zahlen von 1 bis 5 versehen. Mit Farben ginge es wohl auch dann müsste man alphabetisch sortieren.
Die erste Funktion zählt einfach wieviel verschiedene Farben in einer Kombination vorkommen.
Die zweite Funktion all-possibilites nutzt core.logic, also Logisches Programmieren.
Die verschiedenen Kugelpositionen a (Spitze) und b c d die unteren werden definiert.
Dann werden 3 Constraint bestimmungen gesetzt.
Dann wird festgelegt, dass diesen die Farben (Zahlen) von 1 bis 5 zugeordnet werden dürfen.
Die zwei weiteren Zeilen definieren dass der Drehteller immer soweit gedreht werden muß dass Position b die niedrigste Kugel bestimmt. (b <= c und b <= d)
Das andere ist einfach ein Mapping von den verschiedenen Kombinationen auf ein Tuppel anzahl der Farben und der genauen definition der Pyramide.
Das Ergebnis, Speclj macht echt Spaß, wenn die Testcases automatisch aufgerufen werden.
(ns pyramides.core-spec
(:require [speclj.core :refer :all]
[pyramides.core :refer :all]))
(describe "testing pyramides"
(it "275 pyramides"
(should= 275 (count (all-possibilities))))
(it "5 1 colored pyramides"
(should= 5 (count (filter #(== 1 (first %)) (map-by-number-of-colors (all-possibilities))))))
(it "80 2 colored pyramides"
(should= 80 (count (filter #(== 2 (first %)) (map-by-number-of-colors (all-possibilities))))))
(it "150 3 colored pyramides"
(should= 150 (count (filter #(== 3 (first %)) (map-by-number-of-colors (all-possibilities))))))
(it "40 4 colored pyramides"
(should= 40 (count (filter #(== 4 (first %)) (map-by-number-of-colors (all-possibilities))))))
(it "0 5 colored pyramides"
(should= 0 (count (filter #(== 5(first %)) (map-by-number-of-colors (all-possibilities)))))))
Das Ergebnis:
Es gibt danach 275 verschiedene Pyramiden
5 Einfarbige
80 Zweifarbige
150 Dreifarbige
40 Vierfarbige
und 0 Fünffarbige.
Alle Möglichkeiten
[spoiler]
([1 [1 1 1 1]] [2 [2 1 1 1]] [2 [1 2 2 2]] [2 [3 1 1 1]] [2 [1 1 2 1]] [1 [2 2 2 2]] [2 [1 1 1 2]] [2 [1 3 3 3]] [2 [4 1 1 1]] [2 [2 1 2 1]] [3 [1 2 3 2]] [2 [1 1 1 3]] [2 [3 2 2 2]] [2 [2 1 1 2]] [2 [1 1 3 1]] [3 [1 2 2 3]] [2 [2 3 3 3]] [2 [1 4 4 4]] [2 [1 1 2 2]] [2 [5 1 1 1]] [2 [1 1 1 4]] [3 [3 1 2 1]] [2 [2 2 3 2]] [2 [1 1 1 5]] [3 [1 3 4 3]] [3 [2 1 1 3]] [2 [4 2 2 2]] [3 [1 2 2 4]] [3 [3 1 1 2]] [3 [2 1 3 1]] [3 [1 1 2 3]] [3 [1 2 4 2]] [2 [2 2 2 3]] [2 [1 1 4 1]] [1 [3 3 3 3]] [3 [1 3 3 4]] [2 [2 4 4 4]] [3 [1 1 3 2]] [2 [1 5 5 5]] [2 [2 1 2 2]] [3 [1 1 2 4]] [3 [1 2 3 3]] [3 [2 1 1 4]] [3 [1 2 2 5]] [3 [1 1 2 5]] [2 [5 2 2 2]] [3 [4 1 2 1]] [2 [1 1 3 3]] [2 [1 1 5 1]] [2 [3 2 3 2]] [3 [2 1 1 5]] [3 [1 1 4 2]] [3 [2 3 4 3]] [3 [1 1 3 4]] [2 [3 1 1 3]] [3 [1 4 5 4]] [4 [1 2 3 4]] [2 [2 2 2 4]] [3 [1 3 3 5]] [3 [4 1 1 2]] [3 [1 2 5 2]] [3 [1 1 3 5]] [2 [3 1 3 1]] [3 [1 4 4 5]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1 4 2]] [2 [4 4 5 4]] [4 [5 1 3 4]] [3 [4 2 3 4]] [2 [5 4 5 4]] [3 [4 3 3 5]] [4 [5 2 3 4]] [3 [4 2 5 2]] [2 [5 3 3 5]] [4 [4 1 3 5]] [2 [4 4 4 5]] [2 [5 2 5 2]] [3 [5 1 3 5]] [2 [5 4 4 5]] [3 [4 3 5 3]] [3 [4 1 4 3]] [3 [4 2 4 3]] [2 [5 3 5 3]] [4 [4 1 5 2]] [4 [5 1 4 3]] [4 [5 2 4 3]] [3 [5 1 5 2]] [4 [4 2 3 5]] [3 [5 2 3 5]] [2 [4 1 4 4]] [4 [4 1 5 3]] [3 [5 1 4 4]] [3 [5 1 5 3]] [2 [4 3 4 4]] [3 [4 1 4 5]] [3 [5 3 4 4]] [3 [4 1 5 4]] [3 [5 1 4 5]] [3 [5 1 5 4]] [3 [4 1 5 5]] [2 [4 2 4 4]] [2 [5 1 5 5]] [2 [4 4 5 5]] [3 [5 2 4 4]] [4 [4 2 5 3]] [2 [5 4 5 5]] [3 [5 2 5 3]] [3 [4 2 4 5]] [3 [4 3 4 5]] [3 [4 2 5 4]] [3 [5 2 4 5]] [3 [4 3 5 4]] [3 [5 3 4 5]] [3 [5 2 5 4]] [3 [5 3 5 4]] [3 [4 2 5 5]] [3 [4 3 5 5]] [2 [5 2 5 5]] [2 [5 3 5 5]])
[/spoiler]
[1 [1 1 1 1]] bedeutet hierbei eine Farbe kommt vor und die jeweiligen Kugeln haben jeweils die Farbe 1.