20
Letter dice are common in word games. It can be fun to try to spell funny words with boggle dice, for instance. If you grab a handful of dice, chances are you won't be able to spell certain words. This challenge is a generalization of that idea.
Challenge
Given a list of dice which each have at least 1 face and a word, your task is to determine if it is possible to spell that word using the given dice (in which case, it should return a truthy result). Only one letter from each die can be used and a die can be used only once. You do not need to use all of the given dice.
Examples
In a trivial example, with the dice [[A], [C], [T]] and the string CAT, the result is true. BAT would, of course, return false since there are no dice with B on them
If given [[A, E, I, O, U], [A, B, C, T], [N, P, R]] as the set of dice, you would return true for ART, TON, and CUR, but false for CAT, EAT, and PAN because those strings require reusing dice. It should also be fairly obvious that CRAB cannot be spelled with these dice since there are not enough dice.
If given [[A, B, C], [A, E, I], [E, O, U], [L, N, R, S, T]] as the set of dice, you would be able to spell CAT, BEE, BEAN, TEA, BEET, and BAN, but you would not be able to spell LONE, CAB, BAIL, TAIL, BAA, or TON
There may be multiples of the same die. If given [[A, B, C], [A, B, C], [A, B, C]], you would be able to spell CAB, BAA, AAA, etc... but obviously nothing without A, B, or C in it.
Rules
- No exploiting standard loopholes
- This is code-golf, so the shortest code wins.
- You may assume that both words and dice will only be made up of capital letters.
- You may assume that the word will always be at least 1 letter long and that there will always be at least 1 die.
- You may assume that a die will never have more than one of the same letter.
- Input and output may be in any convenient format.
Why making new tags? – user202729 – 2018-05-03T05:27:04.147
Can one take a list (vector) of chars as input (similar format as a dice)? Asking for a friend who'd like to save 27 bytes. – JayCe – 2018-05-03T19:32:45.283
1@JayCe "Input and output may be in any convenient format", so yes. – Beefster – 2018-05-03T19:48:47.663