| Bytes | Lang | Time | Link |
|---|---|---|---|
| 356 | Python 3 56 Bytes | 250127T161822Z | BeardedO |
| 095 | C gcc | 200531T230152Z | Noodle9 |
| 027 | x8664 machine code | 200602T110808Z | anatolyg |
| 039 | 05AB1E | 200602T075442Z | Kevin Cr |
| 048 | Python 2 | 200531T064818Z | ovs |
| 052 | C gcc | 200601T030806Z | dingledo |
| 047 | Ruby n | 200531T125632Z | Kirill L |
| 109 | Io | 200531T095110Z | user9206 |
| 041 | Charcoal | 200531T103031Z | Neil |
| 060 | JavaScript ES6 | 200531T091811Z | Arnauld |
| 058 | Retina | 200531T025939Z | math jun |
| 070 | Brachylog | 200531T030602Z | Unrelate |
Python 3 56 Bytes
OVS Fiddled around and got two more bytes off using your technique.
lambda s:0x194948b501e8c1e42>>int(s[::3]*2,36)%2066%65&1
One byte shorter but produces 1 for the falses and 0 for the trues
lambda s:0x23622480c122c1b1>>int(s[::3]*2,36)%2066%65&1
C (gcc), 125 \$\cdots\$ 101 95 bytes
Saved a byte thanks to ceilingcat!!!
#define f(s)!index(" %&(-.049;ADHJQRSYZis",*s**s*s[l=strlen(s)-1]*s[l-1]%3519%163%108%92+32)
l;
Inputs a string and returns \$1\$ for words meaning 'true' and \$0\$ for words meaning 'false'.
How?
The first, second to last, and last characters of all the word strings form a unique triplet of characters across all words. Multiplying the ASCII values of first character squared and the other two together yields unique 32-bit integers across all words. These numbers modulus values found by a Python script yield a distinct set of integers for all 'false' words in the range \$(0,96)\$. These numbers can then be transformed back to printable ASCII characters by adding \$32\$ to them. Then it's simply a test if a string put through these calculations yields a character that can be found in a given string (also generated by the Python script).
x86-64 machine code, 27 bytes
Hexdump:
6b 01 35 c1 e8 06 6b c8 d3 d1 c1 48 ba 4e 88 00
02 c3 45 88 8b 48 d3 e2 1a c0 c3
A function which receives a pointer to the string in rcx, and returns the result in al.
−1 means true, and 0 means false.
Assembly source code, using ml64 (MASM) syntax:
.CODE
my PROC
imul eax, dword ptr[rcx], 53
shr eax, 6
imul ecx, eax, -45
rol ecx, 1;
mov rdx, 8b8845c30200884eh;
shl rdx, cl;
sbb al, al;
ret;
my ENDP
end
Disassembly, while stopped on a breakpoint at the start of the function:
00007FF73978F4A0 6B 01 35 imul eax,dword ptr [rcx],35h
00007FF73978F4A3 C1 E8 06 shr eax,6
00007FF73978F4A6 6B C8 D3 imul ecx,eax,0FFFFFFD3h
00007FF73978F4A9 D1 C1 rol ecx,1
00007FF73978F4AB 48 BA 4E 88 00 02 C3 45 88 8B mov rdx,8B8845C30200884Eh
00007FF73978F4B5 48 D3 E2 shl rdx,cl
00007FF73978F4B8 1A C0 sbb al,al
00007FF73978F4BA C3 ret
It uses hashing, like many other answers. The hash function uses the first 4 bytes of the string - by luck, all strings are at least 4 bytes long (including terminating zero byte). It does the following:
- Multiply by 53, ignoring overflow
- Shift right by 6 bits
- Multiply by -45, ignoring overflow
- Rotate left by 1 bit
- Access the 64-bit hash table, using 6 LSB of the result
Found by brute-force search. The search space was 8 + 5 + 8 + 5 = 26 bits. The "rotate left" bit count is 1 by luck, which reduces code size by 1 byte, compared to the general "rotate left" case.
05AB1E, 41 39 bytes
.•6ðó_ ï²£Ëý¾Sð7§Ê³®6´¡Žmã•2ôåàI…gawQ~≠
-2 bytes by using a shorter compressed string from @Neil's Charcoal answer, who apparently uses the exact same approach.
Try it online or verify all test cases.
Explanation:
.•6ðó_ ï²£Ëý¾Sð7§Ê³®6´¡Žmã•
# Push compressed string "bibrcrepfagujhjikekrlamaminenwouseteyaza"
2ô # Split it into parts of size 2
å # Check for each whether it's a substring of the (implicit) input-string
à # And check if any is truthy
I # Push the input again
…gawQ # Check that it's equal to string "gaw"
~ # Check if either of the two is truthy by using a bitwise-OR
≠ # And invert the boolean (!= 1)
# (after which the result is output implicitly)
See this 05AB1E tip of mine (section How to compress strings not part of the dictionary?) to understand why .•6ðó_ ï²£Ëý¾Sð7§Ê³®6´¡Žmã• is "bibrcrepfagujhjikekrlamaminenwouseteyaza".
Python 2, 56 48 bytes
thanks to dingledooper for -8 bytes!
lambda s:0x420AF14A5F8266>>hash(s)%3317%890%57&1
All these answers do the same thing:
Convert the string into an unique integer.
Makes these integers smaller by repeated modulo operations. These operations are bruteforced to make the numbers as small as possible while not mixing up the two classes.
Index into a binary lookup table.
Python 3, 59 58 bytes
lambda s:0x48A2D06199310566F06>>int(s[:4],36)%542%400%78&1
lambda s:0x453CCA1066840810431C1>>int(s,36)%2387%1770%86&1
lambda s:0x42744262AEA01A914800A12C>>int(s,36)%155687%95&1
05AB1E, 30 29 28 bytes
4öŽ3¹%Ƶ™%84%o•1±87÷Јù³Í:•&Ā
6öŽ9{%521%76%o•B&¦¿³ʒв F6•&Ā
C (gcc), 55 52 bytes
-3 bytes thanks to @G. Sliepen
f(s){s=0x4240165C085F34>>a64l(s)%19537U%11702%56&1;}
The strategy used is the same as in @ovs's answer. We brute-force values corresponding to each string, making sure that no two truthy and falsey words share the same value. The answer is then extracted from a binary lookup table.
Here, the a64l() function converts a given string into a 32-bit signed integer.
Ruby -n, 54 49 47 bytes
p !/^[fgmryz]a|[ncks][erw]|[bjm][hir]|ep|la|te/
Thanks to Dingus for a byte saved and Value Ink for inspiring another -2.
Io, 109 bytes
-10 bytes thanks to Neil.
method(x,"bi br cr ep fa gu jh ji ke kr la ma mi ne nw ou se te ya za gaw"split select(i,x findSeq(i))size<1)
Io, 119 bytes
Searches for prefixes of existing values.
method(x,"dob fa ga ham an br cr e pate ge j k ma mi ne ni on ps sal shik ra ya za"split select(i,x findSeq(i)==0)size)
Charcoal, 41 bytes
¬∨⁼θgaw⊙⪪”&⌈→⊖L↓&s⦃R⁹CV÷⊕O⸿↔Vf‴λ⌕9↶7”²№θι
Try it online! Link is to verbose version of code. Output is a Charcoal boolean, i.e. - for true, nothing for false. Explanation:
θ Input string
⁼ Equals
gaw Literal string `gaw`
∨ Boolean Or
”...” Compressed string `bibrcrepfagujhjikekrlamaminenwouseteyaza`
⪪ ² Split into substrings of length 2
⊙ Where any is nonzero
№ Count of
ι Current substring in
θ Input string
¬ Boolean Not
Implicitly print
JavaScript (ES6), 63 62 60 bytes
Saved 2 bytes thanks to @Neil
A regular expression that matches all falsy words and none of the truthy ones.
s=>!/ao|mi|ob|w$|[gnst]e|[bck]r|[flz]a|^[ejkmry]|nw/.test(s)
Retina, 68 67 60 58 bytes
^(n?a[^n]|be|ch|gw|p[or]|sa[hn]|h?[itvw]|zh)|as|ss|in|og?r
Regex that matches all truthy values and none of the falsey ones.
Brachylog, 70 bytes
¬{~ṇ"pate
shik
dob
sal
ham"∧"nezabrcrpsangagenifa"ġ₂;?,"yeojrkm"∋∋~a₀}
Takes input through the output variable and outputs through success or failure.