Problem 205
コンテンツ
205 Dice Game
サイコロ遊び。
目の合計なんて、高々36。
import Data.Function (on) import Data.Map (Map, fold, fromListWith, filterWithKey,toList) totals :: [[Integer]] -> Map Integer Integer totals = fromListWith (+).(`zip` (repeat 1)).map sum.sequence p205 :: Double p205 = on (/) fromIntegral wins all where all = on (*) (fold (+) ) peter colin wins = sum [win x colin * n | (x,n) <- toList peter] win x = fold (+) .filterWithKey(k _ -> k < x) peter = totals $ replicate 9 [1..4] colin = totals $ replicate 6 [1..6]
作成者 Toru Mano
最終更新時刻 2023-01-01 (c70d5a1)