| Bytes | Lang | Time | Link |
|---|---|---|---|
| nan | I found a super handy site to help with the issue https//descrambleword.com/ . It is super easy to use | 250516T231631Z | Francia |
| 009 | ayr | 211110T174301Z | ZippyMag |
| 005 | Vyxal | 211109T022832Z | lyxal |
| 028 | K4 | 211110T170320Z | mkst |
| 003 | Vyxal 2.6pre1 | 211109T030323Z | emanresu |
| 049 | Retina | 211109T190134Z | Neil |
| 005 | 05AB1E | 211109T110635Z | Kevin Cr |
| 066 | Python 2 | 211109T161749Z | dingledo |
| 005 | Japt f | 211109T131756Z | AZTECCO |
| 047 | Perl 5 | 211109T115705Z | Kjetil S |
| 038 | Perl 5 + F M5.10.0 | 211109T123120Z | Dom Hast |
| 074 | Python 3.10 | 211109T092933Z | ovs |
| 088 | Python | 211109T083030Z | pxeger |
| 024 | J | 211109T060333Z | Jonah |
| 012 | Charcoal | 211109T053115Z | Neil |
| 053 | Factor + math.combinatorics math.unicode | 211109T053039Z | chunes |
| 046 | Ruby | 211109T042033Z | Dingus |
| 061 | JavaScript Node.js | 211109T033239Z | tsh |
| 004 | Jelly | 211109T021126Z | caird co |
| 009 | Pyth | 211109T014048Z | Scott |
I found a super handy site to help with the issue: https://descrambleword.com/ . It is super easy to use, and in a few seconds, you get your result.
ayr, 10 9 bytes
[#*/&,:/:
Takes the words on the left and the letters on the right
Explained
/: Each left
,: Membership
*/& And then reduce with multiplication
[# Filter words with this mask
*/ 1 0 0 1 0 is the same as ^./ 1 0 0 1 0 but shorter.
Vyxal, 5 bytes
ṖvKf↔
This has to be the first time I've found a use for K on strings lol
Explained
ṖvKf↔
Ṗ # All permutations of the input word
vK # and get the divisors (substrings that split the string into more than once piece - idk how this actually makes this work)
f # flatten that
↔ # remove words from the input list that aren't in ^
K4, 28 bytes
Solution:
{y@&x{&/1>(#:'=y)-#:'=x}/:y}
Examples:
Count letter occurrences, subtract and spit out words that match...
q)k){y@&x{&/1>(#:'=y)-#:'=x}/:y}["trom";("as";"to";"too";"or")]
"to"
"or"
q)k){y@&x{&/1>(#:'=y)-#:'=x}/:y}["asto";("as";"so";"to";"oats")]
"as"
"so"
"to"
"oats"
q)k)()~{y@&x{&/1>(#:'=y)-#:'=x}/:y}["zzyzx";("as";"to";"so")]
1b
Explanation:
{y@&x{&/1>(#:'=y)-#:'=x}/:y} / the solution
{ } / lambda taking implicit x and y args
x{ }/:y / apply inner lambda to x and each y
=x / group x
#:' / count length of each group
- / subtract from
( ) / do this together
=y / group y
#:' / count length of each group
1> / 1 greater than subtraction result?
&/ / all
& / indices where true
y@ / index into y with these indices
Alternatives:
{y@&&/'1>(#:''=:'y)-\:#:'=x}, also 28 bytes
Vyxal 2.6pre1, 5 3 bytes
Þ×↔
Don't Try it Online! (the site runs a few commits 2.4.1)
Haha builtin go brr.
-2 thanks to Lyxal.
↔ # The elements in common between
Þ× # All combinations of the letters
# And the input.
Retina, 49 bytes
A`^|(.)(.*\1)*(?<!^.*(?(2)^)(?<-2>.*\1)*\1(.|¶)+)
Try it online! Takes newline-separated input but link is to test suite that splits on commas for convenience. Explanation:
A`^|
Delete the first line, plus...
(.)(.*\1)*
... any lines that have more of a particular letter...
(?<!^.*(?(2)^)(?<-2>.*\1)*\1(.|¶)+)
... than the first line does.
05AB1E, 7 5 bytes
怜˜Ã
-2 bytes thanks to @ovs.
Inputs in the order letters, words-list.
Try it online or verify all test cases.
Explanation:
æ # Get the powerset of the (implicit) first input-string of letters
€œ # Get the permutations of each string in this list
˜ # Flatten this nested list to a single list of strings
à # Keep the words from the second (implicit) input-list that are also in this list
# (after which the result is output implicitly)
Python 2, 66 bytes
lambda s,l:[w for w in l if all(w.count(c)<=s.count(c)for c in w)]
Japt -f, 6 5 bytes
øVáUl
-f flag to output the elements of first input
that return a truthy value when passed through
ø - true if word contains any of:
Vá - permutations of alphabet
Ul - of same length of word hence equal
Or try that
Perl 5, 52 47 bytes
sub{$c=pop;grep{$C=$c;!grep{$C!~s/$_//}/./g}@_}
(shaved 5 extra bytes from Dom Hastings' suggestions)
Perl 5 + -F -M5.10.0, 38 bytes
say grep{$t=$_;$t=~s/$_// for@F;!$t}<>
Explanation
The letters (first line of input) are implicitly stored in @F via the -F flag.
We grep through the word list (<>), temporarily storing the word ($_) in $t, then for each letter in @F, s///ubstitute it ($_) for the empty string, returning a truthy value (which includes the word in the set to be printed by say) if $t is now empty (all letters of the word were removed because they exist in the input letters).
Python 3.10, 74 bytes
lambda w,l:[x for x in l if C(x)<=C(w)] from collections import* C=Counter
In versions before 3.10 C(x)<=C(w) would have been not C(x)-C(w) instead.
Python, 88 bytes
lambda a,w:filter(" ".join(map("".join,permutations(a))).count,w)
from itertools import*
Assumes the words don't contain spaces, but the " " can be changed to any other character that the words won't contain.
Unusually for Python, this declarative approach (map+filter) is shorter than a list comprehension.
Charcoal, 12 bytes
Φη⬤鬛№ιλ№θλ
Try it online! Link is to verbose version of code. Explanation:
η Word list
Φ Filtered where
ι Current word
⬤ All letters satisfy
№ιλ Count of letter
¬› Does not exceed
№θλ Count available
Implicitly print
Factor + math.combinatorics math.unicode, 53 bytes
[ <permutations> '[ _ [ subseq? ] with ∃ ] filter ]
In plain English, select all words from the dictionary that appear in any permutation of the scrabble letters.
Ruby, 46 bytes
->b,a{a.select{|w|d=b*1;w.all?{|c|d[c]&&=''}}}
Takes the list of tiles as a string; words are input and output as lists of characters. The inconsistent formats can be avoided at a cost of a few extra bytes: 47 bytes to use lists of characters exclusively and 52 bytes for strings.
All variants work the same way. For each letter of a word, remove the first occurrence of that letter from the list of tiles or return nil (falsy) if there is no such tile. The word can be formed if this procedure succeeds for all its letters.
JavaScript (Node.js), 61 bytes
s=>l=>l.filter(w=>w.map(g=c=>g|=w[c]=s.indexOf(c,w[c]+1))|~g)
Input / output words as list of characters.
Jelly, 4 bytes
œ&ƑƇ
How it works
œ&ƑƇ - Main link. Takes a list of words L on the left, a word W on the right
Ƈ - Keep those words from L such that:
Ƒ - They are unchanged after taking:
œ& - The multiset intersection with W
Pyth, 9 bytes
@E{.nyM.p
@E{.nyM.p
yM.P // Collect all subsets of all permutations of the input
{.n // -> Flatten and de-duplicate the list
E // Read the word list
@ // Get the intersections of the two lists.