I came across this picture, which I initially questioned and thought about posting to Skeptics. Then I thought they'll only tell me if this one case is true, but wouldn't it be great to know how true any "rule" really is? Today you're going program a skeptic-bot
Challenge
Write a program or function which when given a dictionary of valid words and a rule determines if the rule is well applied
Rules
- The dictionary is "words.txt" taken from here. Your submission must theoretically be able to review all words in the file, but for testing you may use a shortened list
- "Rules" come in the form
x before y except <before/after> z
. Your submission may take that input in any reasonable form, some examples below - Compliance is defined as: "There is an adjacent
x
andy
in the word in the right order that are in the reverse order if before/afterz
" - Non-compliance is defined as: "There is an adjacent
x
andy
in the word in the incorrect order or they are not reverse if before/afterz
" - Rules are evaluated case insensitive
- Output or return a truthy value if the number of compliant words in the dictionary is greater than the number of non-compliant words, otherwise output a falsey value. Submissions cannot end in errors.
- This is code-golf, so shortest submission in bytes wins
Example input:
["i","e","-","c"] #list of values, "-" denotes "after"
[105,101,-99] #list of values as ASCII numbers, "-99" denotes "after"
"ieac" #string of values abbreviated
Test Cases
Below are sample cases as inputs, for clarity I list the matching words but this is not required
Example dictionary: ["caught", "lemon", "simplified", "queue", "qwerty", "believe", "fierce", "receive", "science", "foreign", "weird", "quit"]
Input: "I before E except after C"
Compliant: simplified, believe, fierce, receive
Noncompliant: science, foreign, weird
Output: Truthy
Input: "Q before U except before E"
Compliant: quit
Noncompliant: queue
Output: Falsey
Input: "C before E except before E"
Compliant: fierce, receive, science
Noncompliant:
Output: Truthy