Commit 1f2058ec by Stuart Kurtz

Day 21, with major part a cleanups and improved comments.

parent 3c517c8b
Showing with 8 additions and 7 deletions
......@@ -20,13 +20,14 @@ splits = M.assocs $ roll 3 (M.singleton 0 1) where
universes :: Array (Int,Int,Int,Int) (Integer,Integer)
universes = array bds [(p, score p) | p <- range bds] where
bds = ((0,1,0,1),(20,10,20,10))
score (xScore,xPos,yScore,yPos) = sumPairs
[ (c * losers, c * winners)
| (r,c) <- splits
, let nPos = ((xPos + r - 1) `mod` 10) + 1
nScore = xScore + nPos
(winners,losers) = univ yScore yPos nScore nPos
]
score (xScore,xPos,yScore,yPos) =
sumPairs
[ (c * losers, c * winners)
| (r,c) <- splits
, let nPos = ((xPos + r - 1) `mod` 10) + 1
nScore = xScore + nPos
(winners,losers) = univ yScore yPos nScore nPos
]
sumPairs = foldr1 (\(a,b) (c,d) -> (a+c,b+d))
univ xScore xPos yScore yPos
| yScore >= 21 = (1,0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment