tag:blogger.com,1999:blog-9871512.post113771091738628914..comments2022-09-03T20:56:46.577-04:00Comments on Tumbolia: Haskelljtohttp://www.blogger.com/profile/03968844388108605008noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-9871512.post-68441511606212982222007-01-12T16:26:00.000-05:002007-01-12T16:26:00.000-05:00Turns out there is a better way. Same basic idea,...Turns out there is a better way. Same basic idea, but using Data.List.mapAccumL instead of doing the accumulator thing manually:<br /><br />import Data.Map<br />import Data.List<br /><br />histogram = mapAccumL acc empty<br />__where<br />____acc m k = let m' = insertWith (+) k 1 m in<br />______(m', findWithDefault 0 k m')<br /><br />random_trial target = any (>= target) . snd . histogramVineethttps://www.blogger.com/profile/12361589059366845911noreply@blogger.comtag:blogger.com,1999:blog-9871512.post-67374171653946941132007-01-08T10:29:00.000-05:002007-01-08T10:29:00.000-05:00Thanks, vineet, but I sure hope there's a better w...Thanks, vineet, but I sure hope there's a better way.jtohttps://www.blogger.com/profile/03968844388108605008noreply@blogger.comtag:blogger.com,1999:blog-9871512.post-77058111181013883102007-01-08T01:51:00.000-05:002007-01-08T01:51:00.000-05:00I'm also just starting out with Haskell, so this m...I'm also just starting out with Haskell, so this may not be the best way to do it, but you can indeed build up a histogram as you go. Here I accumulate a map of frequencies of each item in the list, and immediately return True as soon as a count reaches the target value:<br /><br />import Data.Map<br /><br />random_trial target bs = random_trial' bs empty<br />__where<br />__random_trial' [] _ =Vineethttps://www.blogger.com/profile/12361589059366845911noreply@blogger.com