In Magic: the Gathering, mages (known as "planeswalkers") battle each other by casting spells. Spells cost mana. Five colors of mana exist: White, Blue, Black, Red, and Green, represented as {W}, {U}, {B}, {R}, and {G}, respectively.
A spell's cost is slightly more complex. The cost can be any combination of the following:
- One or more colors
- One or more colorless, represented as {X}, where X is a positive integer
- One or more hybrids, represented as {Y/Z}, where Y and Z are either a color (represented by one of the five letters) or colorless, represented by a positive integer
The following rules apply when attempting to cast a spell:
- A color in a cost must be satisfied by one mana of that color
- A colorless cost {X} may be satisfied by X mana of any color
- A hybrid cost {Y/Z} may be satisfied by satisfying either Y or Z
- Note that braces are not nested
- Y and Z are not hybrid
Write a program or function that, given a pool of mana and a cost, prints or returns true (or some truthy value) if and only if the mana in that pool can satisfy the cost, else false (or some falsy value).
A mana pool is a non-empty string of the format:
Color1,Color2,Color3,...,Colorn-1,Colorn
A cost is a non-empty string of the format:
Cost1,Cost2,Cost3,...,Costn-1,Costn
Examples
In the format Pool Cost -> ExpectedOutput
(with a space between Pool and Cost):
{R},{R},{G},{B},{R} {4},{R} -> True
{G},{G},{G},{G},{W},{W},{W} {2/W},{2/U},{2/B},{2/R},{2/G} -> False
{G},{G},{R} {R/G},{G/B},{B/R} -> True
{R},{R},{R},{G} {1},{G},{2/G}-> True
{R} {R},{R},{R},{R},{R} -> False
{W},{R},{R} {2/W},{W/B} -> True
{U},{U} {1} -> True
{W},{R},{G} {1},{2} -> True