fork download
  1. ; https://p...content-available-to-author-only...r.net/problem=205
  2.  
  3. (defn cart [& lists]
  4. (let [syms (for [_ lists] (gensym))]
  5. (eval `(for [~@(mapcat #(list %1 `'~%2) syms lists)]
  6. (list ~@syms)))))
  7.  
  8. (defn project-euler-205 []
  9.  
  10. (let [rolls (fn [n d]
  11. (->> (range 1 (inc d))
  12. (repeat n)
  13. (apply cart)
  14. (map #(apply + %))
  15. frequencies))
  16.  
  17. peter-rolls (rolls 9 4)
  18. colin-rolls (rolls 6 6)
  19.  
  20. all-results (* (apply + (vals peter-rolls))
  21. (apply + (vals colin-rolls)))
  22.  
  23. peter-wins (apply + (for [[pk pv] peter-rolls
  24. [ck cv] colin-rolls
  25. :when (> pk ck)]
  26. (* pv cv)))]
  27.  
  28. (/ peter-wins all-results)))
  29.  
  30. (println (project-euler-205))
Success #stdin #stdout 4.17s 389120KB
stdin
Standard input is empty
stdout
48679795/84934656