Evaluate Words Based on "Rules" (Skeptics.SE Crossover)
Python3, 105 103 bytes
This is my first golf here so be kind =)
-2 bytes tanks to Chas Brown
lambda d,b,x,y,z:sum((x+y in i)-2*((z*b+x+y+z)[:3]in i)-(y+x in i)+2*((z*b+y+x+z)[:3]in i)for i in d)>0
Takes the dictionary d
as any iterator of strings; a boolean 'b' (True
being after
); and the three letters x,y,z
as Strings;
Try it online!
Explanation: might add later
Java 8, 210 bytes
(D,a,b,c,f)->D.stream().filter(w->w.contains(a+b)&!w.contains(f?c+a+b:a+b+c)|w.contains(f?c+b+a:b+a+c)).count()>D.stream().filter(w->w.contains(b+a)&!w.contains(f?c+b+a:b+a+c)|w.contains(f?c+a+b:a+b+c)).count()
Takes the dictionary D
as a java.util.List<String>
; the three letters a,b,c
as Strings; and whether it's after or before as a boolean f
(truthy being 'after').
EDIT: Surprisingly enough using two .matches
with regexes instead of the two times three .contains
is longer. And creating variables for f?c+a+b:a+b+c
and f?c+b+a:b+a+c
is also 1 byte longer.
Try it online.
Explanation:
(D,a,b,c,f)-> // Method with List, 3 Strings, boolean parameters & boolean return
D.stream() // Stream the given dictionary-List
.filter(w-> // Filter the words by:
w.contains(a+b) // If the word contains `a+b`
&!w.contains(f? // If the flag is true (after):
c+a+b // And the word does not contain `c+a+b`
: // Else (before):
a+b+c) // And the word does not contain `a+b+c`
|w.contains(f? // If the flag is true (after):
c+b+a // Or the word contains `c+b+a`
: // Else (before):
b+a+c)) // Or the word contains `b+a+c`
.count() // And get the amount of words left in the filtered result
> // And return whether this is larger than:
D.stream() // Stream of the given dictionary again
.filter(w-> // Filtered by:
w.contains(b+a) // If the word contains `b+a`
&!w.contains(f? // If the flag is true (after):
c+b+a // And the word does not contain `c+b+a`
: // Else (before):
b+a+c)// And the word does not contain `b+a+c`
|w.contains(f? // If the flag is true (after):
c+a+b // Or the word contains `c+a+b`
: // Else (before):
a+b+c)) // Or the word contains `a+b+c`
.count() // And get the amount of words left in the filtered result
Python 2, 109 107 bytes
lambda D,x,y,r,c:sum((((' '+w+' ')[w.find(p)+3*r]!=c)^(p==y+x))*2-1for p in(x+y,y+x)for w in D if p in w)>0
Try it online!
Takes Dictionary and rule input as D,x,y,r,c
with r=0
to mean 'before' and r=1
to mean 'after'.