Skip to content

Instantly share code, notes, and snippets.

@taksuyu
Created January 26, 2015 21:39
Show Gist options
  • Save taksuyu/081db7fce69159d7deef to your computer and use it in GitHub Desktop.
Save taksuyu/081db7fce69159d7deef to your computer and use it in GitHub Desktop.

You can get some interesting information with the use of MultiSets in haskell

This example is finding combinations of sequences with a given hand in mahjong. A more indepth explanation can be found here

runFilter $ MS.fromList
[ Suits Character One, Suits Character One, Suits Character One, Suits Character One
, Suits Character Two
, Suits Character Three
, Suits Character Four
, Suits Character Five
, Suits Character Six
, Suits Character Seven
, Suits Character Eight
, Suits Character Nine, Suits Character Nine, Suits Character Nine
]

returns this really obscure MultiSet (Maybe Run).

fromOccurList
[(Nothing,4)
,(Just (Suits Character One  ,Suits Character Two  ,Suits Character Three),4)
,(Just (Suits Character Two  ,Suits Character Three,Suits Character Four) ,1)
,(Just (Suits Character Three,Suits Character Four ,Suits Character Five) ,1)
,(Just (Suits Character Four ,Suits Character Five ,Suits Character Six)  ,1)
,(Just (Suits Character Five ,Suits Character Six  ,Suits Character Seven),1)
,(Just (Suits Character Six  ,Suits Character Seven,Suits Character Eight),1)
,(Just (Suits Character Seven,Suits Character Eight,Suits Character Nine) ,1)
]

The amount of information that can be inferred is quite amazing with this simple check.

  • Anything that didn't work returned Nothing
  • If there was multiple of a specific tile and had a successful run then it'll have multiple of the number
    • As shown with the first found run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment