; https://p...content-available-to-author-only...r.net/problem=205
(defn cart [& lists]
(let [syms (for [_ lists] (gensym))]
(eval `(for [~@(mapcat #(list %1 `'~%2) syms lists)]
(list ~@syms)))))
(defn project-euler-205 []
(let [rolls (fn [n d]
(->> (range 1 (inc d))
(repeat n)
(apply cart)
(map #(apply + %))
frequencies))
peter-rolls (rolls 9 4)
colin-rolls (rolls 6 6)
all-results (* (apply + (vals peter-rolls))
(apply + (vals colin-rolls)))
peter-wins (apply + (for [[pk pv] peter-rolls
[ck cv] colin-rolls
:when (> pk ck)]
(* pv cv)))]
(/ peter-wins all-results)))
(println (project-euler-205))
OyBodHRwczovL3AuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLnIubmV0L3Byb2JsZW09MjA1CgooZGVmbiBjYXJ0IFsmIGxpc3RzXQogIChsZXQgW3N5bXMgKGZvciBbXyBsaXN0c10gKGdlbnN5bSkpXQogICAgKGV2YWwgYChmb3IgW35AKG1hcGNhdCAjKGxpc3QgJTEgYCd+JTIpIHN5bXMgbGlzdHMpXQogICAgICAgICAgICAgKGxpc3QgfkBzeW1zKSkpKSkKCihkZWZuIHByb2plY3QtZXVsZXItMjA1IFtdCiAgCiAgKGxldCBbcm9sbHMgKGZuIFtuIGRdCiAgICAgICAgICAgICAgICAoLT4+IChyYW5nZSAxIChpbmMgZCkpCiAgICAgICAgICAgICAgICAgIChyZXBlYXQgbikKICAgICAgICAgICAgICAgICAgKGFwcGx5IGNhcnQpCiAgICAgICAgICAgICAgICAgIChtYXAgIyhhcHBseSArICUpKQogICAgICAgICAgICAgICAgICBmcmVxdWVuY2llcykpCiAgICAgICAgCiAgICAgICAgcGV0ZXItcm9sbHMgKHJvbGxzIDkgNCkKICAgICAgICBjb2xpbi1yb2xscyAocm9sbHMgNiA2KQogICAgICAgIAogICAgICAgIGFsbC1yZXN1bHRzICgqIChhcHBseSArICh2YWxzIHBldGVyLXJvbGxzKSkKICAgICAgICAgICAgICAgICAgICAgICAoYXBwbHkgKyAodmFscyBjb2xpbi1yb2xscykpKQogICAgICAgIAogICAgICAgIHBldGVyLXdpbnMgKGFwcGx5ICsgKGZvciBbW3BrIHB2XSBwZXRlci1yb2xscwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgW2NrIGN2XSBjb2xpbi1yb2xscwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgOndoZW4gKD4gcGsgY2spXQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoKiBwdiBjdikpKV0KICAgIAogICAgKC8gcGV0ZXItd2lucyBhbGwtcmVzdWx0cykpKQoKKHByaW50bG4gKHByb2plY3QtZXVsZXItMjA1KSk=