How secure are my locks?
Python, 253 246 bytes
m=lambda a,b:min(sorted(a),sorted(b))
def w(s):
if type(s)!=list:return[s]
if len(s)==1:return s
k=w(s[0])
z=w(s[2])
if s[1]=="|":return m(k,z)
return k+z
r=[]
for i in n:r+=[(i,sorted(w(i),reverse=1))]
sorted(r,reverse=1,key=lambda x:x[1])
Perl 6: 132 124 bytes
{reverse .sort: {use MONKEY-SEE-NO-EVAL;my &infix:<|>={|$^a,|$^b}
min map *.flat.sort.squish.reverse,EVAL .trans('&'=>'X')}}
A lambda that takes a list of lines as input.
It generates the sort key for each line as follows:
- Declare
|
as a list concatenation operator within the lexical scope. - Replace
&
in the string withX
, the Perl 6 cartesian product operator. - Eval the string (which unfortunately requires the ghastly
MONKEY-SEE-NO-EVAL
pragma), yielding all possible combinations of keys that open the door. - Post-process the lists and pick the "least secure" combination.