Commit 423aa87b by Stuart Kurtz

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

parent 3a60a6d5
Showing with 8 additions and 8 deletions
......@@ -14,24 +14,24 @@ splits = M.assocs $ roll 3 (M.singleton 0 1) where
roll 0 m = m
roll n m = roll (n-1) . M.unionsWith (+) . map ((`M.mapKeys` m) . (+)) $ [1,2,3]
-- universes ! (xScore,xPos,yScore,yPos) = (losers,winners)
-- universes ! (xCount,xPos,yCount,yPos) = (losers,winners)
-- where player X will make the next move.
universes :: Array (Int,Int,Int,Int) (Integer,Integer)
universes = array bds [(p, score p) | p <- range bds] where
universes = array bds [(p, counts p) | p <- range bds] where
bds = ((0,1,0,1),(20,10,20,10))
score (xScore,xPos,yScore,yPos) =
counts (xCount,xPos,yCount,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
nScore = xCount + nPos
(winners,losers) = univ yCount yPos nScore nPos
]
sumPairs = foldr1 (\(a,b) (c,d) -> (a+c,b+d))
univ xScore xPos yScore yPos
| yScore >= 21 = (1,0)
| otherwise = universes ! (xScore,xPos,yScore,yPos)
univ xCount xPos yCount yPos
| yCount >= 21 = (1,0)
| otherwise = universes ! (xCount,xPos,yCount,yPos)
diracGame :: Int -> Int -> (Integer,Integer)
diracGame p1 p2 = universes ! (0,p1,0,p2)
......
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