# Untitled

By: a guest on Mar 25th, 2012  |  syntax: Haskell  |  size: 0.98 KB  |  hits: 43  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. module Main
2. where
3.
4. import qualified Data.List as L
5. import Control.Applicative
6.
7. main = print \$ sum2 d3_5 []
8.
9. d :: [Integer]
10. d = [1..20]
11.
12. d3 = [ (d1, d2, d3) | d1 <- d,
13.                       d2 <- d,
14.                       d3 <- d ]
15.
16. up6 a | a<6 = 6
17.       | otherwise = a
18.
19. d3s = map (\(a,b,c) -> up6 (div (a+b+c+2) 3))
20.
21. d3sr :: [Integer] -> [(Integer ,Integer)]
22. d3sr (h:t)  = _d3sr [] (h, 1) t
23.
24. _d3sr a t [] = t:a
25. _d3sr a (v,c) (h:t)
26.                  | (v == h)  = _d3sr a (v, c+1) t
27.                  | otherwise = _d3sr ((v, c):a) (h, 1) t
28.
29. d3r = ( d3sr .( L.sort . d3s ) ) d3
30.
31. d3_6 = [ [d1, d2, d3, d4, d5, d6] | d1 <- d3r,
32.                                     d2 <- d3r,
33.                                     d3 <- d3r,
34.                                     d4 <- d3r,
35.                                     d5 <- d3r,
36.                                     d6 <- d3r ]
37. d3_6sort = map (L.sortBy (\(a1,_) (a2,_) -> a1 `compare` a2)) d3_6
38. d3_5 = map (\(_:a) -> a) d3_6sort
39.
40. roll5 = pure ( foldl1 sum_rolls )  <*> d3_5