For more MtG-goodness: Magic: The Gathering Combat with Abilities
Premise:
In Magic: the Gathering, you cast spells by paying their mana cost by tapping lands for the required amount. These lands can produce one of the five colors which are:
- White (W)
- Blue (U)
- Black (B)
- Red (R)
- Green (G)
The cost is made up of two parts: a number which is the generic mana requirement, and a series of symbols representing the colored mana requirement. The number is the generic mana cost and can use any color of mana to satisfy it, e.g. (3)
can be paid with WGG
. The symbols are a 1:1 requirement of a specific color. e.g. WWUBR
would require 2 white mana, 1 blue, 1 black and 1 red. The Generic part will always come before the Colored part. As a reminder, (0)
is a valid cost and must be handled.
You can have costs that are entirely generic, or entirely colored, or both. For example, the following card has a cost of 4BB and is be paid with 4 of whatever colored mana and 2 black mana:
Lands in this challenge will each produce one mana. However, we will consider lands that can produce multiple colors but still only yield 1 mana. E.g. G
will produce a green mana, WG
can produce either 1 white or 1 green.
Input:
You will be given two inputs, a card's cost and a list of lands.
The card's cost can either be a string, or a tuple containing a number and a string for the colored part. If there's no generic part, you can pad the string/tuple with a 0.
The land list will be a list of strings where each one is what a given land can produce. This list can be empty (you have no lands). You can also take this as a list of ints using bit-mask logic but post your scheme if you do. Order is also up to you if it matters, otherwise it'll be assumed in WUBRG
order.
#Example input formats
"4BB", ("WG","B","B") #
(4,"BB"), (7,3,3) #Both should return falsy
Output:
A truthy
value if you can successfully pay the cost given your lands and a falsey
value if you cannot.
Rules:
- You'll be guaranteed valid input
- Mana will be assumed to always be in "WUBRG" order. If you want a different order, state so in your answer.
- Colors will always be grouped in the cost, e.g. "WWUBBRG"
- Input will use either all Uppercase or all lowercase, your choice.
- You should be able to handle regex
127[WUBRG]{127}
and 254 lands. - Standard loopholes forbidden
- This is code-golf, shortest answer per language wins
Examples:
"0", ("") => 1
"1BB", ("WG","B","B") => 1
"BB", ("WG","B","B") => 1
"WB", ("WG","B","B") => 1
"1UB", ("W","U","B") => 1
"1BB", ("WB","WB","WG") => 1
"1", ("WG","B","B") => 1
"1BB", ("WGR","WB","WB") => 1
"WUBRG", ("W","U","B","R","G") => 1
"1WWUBB", ("W","WG","U","B","B","R") => 1
"10BB", ("WGR","WB","WB","B","B","B","B","B","B","B","B","B") => 1
"R", ("") => 0
"4", ("WG","B","B") => 0
"1BB", ("WG","WB") => 0
"1UB", ("WG","W","UB") => 0
"1UBR", ("W","WG","UBR") => 0
"WUBRG", ("WUBRG") => 0
"1WWUBB", ("W","WG","U","B","B") => 0
"10UU", ("WGR","WB","WB","B","B","B","B","B","B","B","B","B") => 0