Skip to content

Instantly share code, notes, and snippets.

@Solonarv
Created September 12, 2020 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Solonarv/1c2c644b03f2d04b39bfb9c64a7bac3e to your computer and use it in GitHub Desktop.
Save Solonarv/1c2c644b03f2d04b39bfb9c64a7bac3e to your computer and use it in GitHub Desktop.
Number of playable cards in hand with Snecko Eye and energy relic (Slay the Spire).
import System.Random
import Data.Monoid
import Control.Applicative
import Control.Monad
randomRsIO range = randomRs range <$> newStdGen
numPlayables :: Int -> [Int] -> Int
numPlayables energy costs = zeros + nonzeros
where
zeros = length $ filter (== 0) costs
subsets = filterM (const [False, True]) (filter (> 0) costs)
playableSubsets = filter ((<= energy) . sum) subsets
nonzeros = maximum (length <$> playableSubsets)
main = do
putStrLn "Hand size?"
handSize <- readLn
putStrLn "Energy?"
energy <- readLn
putStrLn "How many hands to draw?"
handsDrawn <- readLn
playedCards <- replicateM handsDrawn $ do
costs <- replicateM handSize (randomRIO (0,3))
return (numPlayables energy costs)
let (Ap (ZipList summary), Sum total) = summarize handSize playedCards
forM_ (zip [0 :: Int ..] summary) $ \(n, iters) -> do
putStrLn $ show n <> " playables: " <> show (getSum iters)
putStrLn $ "Average: " <> show (fromIntegral total / fromIntegral handsDrawn) <> " playables"
summarize :: Int -> [Int] -> (Ap ZipList (Sum Int), Sum Int)
summarize handSize = foldMap go
where go n = (Ap $ ZipList [Sum (if n == i then 1 else 0) | i <- [0..handSize]], Sum n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment