42
You want to open a new zoo. It'll be amazing. But being the cheapskate that you are, you only want to afford three-letter animals (everyone knows that an animal's cost is proportional to the length of its name). There goes your dream of making people pay to see an elephant
. But suddenly you have a brilliant idea. If you just place the animals correctly in the pen, you can create the optical illusion of an elephant
! Here is a top-down view of your new "elephant compound":
elk
eel
pig
hog
ant
-------- (fence)
^
| viewing direction
Haha, those gullible visitors!
Yes, this is how perception works.
The Challenge
Given a non-empty word consisting only of lowercase English letters, determine if it can be formed from overlapping the following 30 three-letter animal words:
ant ape asp ass bat bee boa cat cod cow
dab dog eel elk emu fly fox gnu hog ide
jay kea kob koi olm owl pig rat ray yak
Yes, there are more than 30, but that's a nice round number.
You may optionally receive this list as input (in any reasonable list or string format, as long as it's not pre-processed). You'll probably want to do this, unless reading and processing this input list is much more expensive than hardcoding and compressing it in your language of choice. Note that even if you take the list as input you may assume that it will always be exactly this list, so if your code relies on the passed list being 30 elements long and not containing a word with z
, that's fine.
Each word can be used multiple times. Animals cannot be cut off at the ends, only partially hidden by other animals. So ox
is not a possible string, even though we have fox
.
Output should be truthy if this is possible, and falsy otherwise.
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
Your code should handle any of the test cases in a few seconds.
Standard code-golf rules apply.
More Examples
- Any one- or two-letter word is obviously falsy.
- So is any three-letter word which is not in the above list.
- Even though we have
gnu
andrat
,gnat
is falsy since there's no way to arrange them such that you only see two letters of each (we don't want to cut animals into thirds).
Some truthy examples:
pigment
ant
bee
olm
pig
antioxidant
fox
koi ide
ant ant
Test Cases
Most of the test cases were taken from running a reference implementation against a dictionary. The last few "words" were generated randomly and are just there to ensure that submissions are sufficiently efficient.
Truthy:
ant
owl
bass
pride
bobcat
peafowl
elephant
hedgehogs
crocodile
antidemocrat
aspidoganoidei
biodegradability
angioelephantiasis
propreantepenultimate
acategnukeaidabeleenaspcodcoidyakwakoasshogattkjaypigkobolcodidaskearaywelkwboaxbeeuflapaspoapemaassaaspeewoglmabiemuwjadogacagnuepigjaycownbatjaemuifoxkeaeekekeagratsseeluejdoghogaolmgpigbeaeelemulasphogjaydabemukgnunueifoasdoglrayyadogpewlayroassasslgnuaspyyakkbokeaodxilopgnuasppigkobelratelkolmakob
koigdgaspslycoyakehrdabowbatdkkeapogkobelrowlyarpidepetlfoxeboaiderbeefoxbgnuapeocowgiecowlkoieeltbategspemuideatdogbeeecatgeaoccattbbeassgnasolkeaflyelkaognubeeabrratoccolmobodoglyelraywelkoxantowleedrayflypeappigogatraoyakccpiganaaspkobabjaspkointantybjbeeanolmuijaylratojaynueidflyjarayabatmmpigtfly
eolmantjkobeeaorayogaowldfoxayeassapibatmflylyraelaspsseolmbelkkaoantlmufodasgnueantaidenthyakcodoxuepigodggnuantatlcatnuuelkpemucbapeeoiahdogplkowletbatdrayarayoaelkgrayodcatgkantewkobeljaybeeyfkobtbdabadoghbatfoxtflygaspdeidogtowlkeaolmyraelfleelejayehogowlccatoxeabiemkobpigolmdkobrcidekyakabboyidep
Falsy:
a
ox
ram
bear
koala
antelope
albatross
zookeeper
salamander
caterpillar
hippopotamus
koigdgaspslycoyakehrdabowbatdkkeapogkobelrowlyarpidepetlfoxeboaiderbeefoxbgnuapeocowgiecowlkoieeltbategspemuideatdogbeezcatgeaoccattbbeassgnasolkeaflyelkaognubeeabrratoccolmobodoglyelraywelkoxantowleedrayflypeappigogatraoyakccpiganaaspkobabjaspkointantybjbeeanolmuijaylratojaynueidflyjarayabatmmpigtfly
koigdgaspslycoyakehrdabowbatdkkeapogkobelrowlyarpidepetlfoxeboaiderbeefoxbgnuapeocowgiecowlkoieeltbategspemuideatdogbeeecatgeaoccattbbeassgnasolkeaflxelkaognubeeabrratoccolmobodoglyelraywelkoxantowleedrayflypeappigogatraoyakccpiganaaspkobabjaspkointantybjbeeanolmuijaylratojaynueidflyjarayabatmmpigtfly
beyeodpgspeclxlkbkaylldnceepkocbdmymsaogsowpbawbauaioluaaagaetdoaoialeoxaagspoelegflpylptylnolnatrjabaorkdteeydloiebbptatdtfdfgoodtbkoafmounbduaffcrfelcnawmxaskgaoenaattbaobgbgabnhkesbgaaaaotafkiiieatworginaeowaehuddegooaalowaoososaksahoimkulbtoadyyelkcmkacbuostadppcuglbnmotedfgfkoleldonknemomnmoutykg
I'm still taking suggestions for a better title... – Martin Ender – 2016-01-27T14:44:54.067
You may optionally receive this list as input
- does that mean it doesn't count towards the score, whereas hard-coding it would? – marinus – 2016-01-27T14:52:07.773@marinus Yes. So you'll probably want to take it as additional input, unless reading more than one string on input is really cumbersome in your language of choice. (I don't want to allow hardcoding + "if you do, subtract it from your score", because then you'll get people hardcoding and compressing it in, which would essentially give them a bonus to their score.) – Martin Ender – 2016-01-27T14:54:30.667
Does "function (out) parameter" include parameters by reference?
– mınxomaτ – 2016-01-27T15:04:55.000@mınxomaτ Yes it does.
– Martin Ender – 2016-01-27T15:07:55.487What do you have against rams? – Luke – 2016-01-27T15:12:33.217
@Luke "Yes, there are more than 30, but that's a nice round number." ;) (Specifically, I deliberately left out names for female, male and young animals like ram, ewe, doe, cub as well as lesser known animals like dzo... and yes I did include the female "cow", but that's widely used as a synonym for "cattle".) – Martin Ender – 2016-01-27T15:20:37.340
5I can't believe I missed the "round number" comment in the sandbox. Shame on you, sir! Around these parts 32 is a round number, not 30. (And it's not entirely try that you left out names for male animals - see hog). – Peter Taylor – 2016-01-27T16:34:08.413
@PeterTaylor oh, I thought hog referred to wild pigs, not male pigs. Well... – Martin Ender – 2016-01-27T17:19:42.730
"Animal Magic"? – Neil – 2016-01-27T22:34:34.510
"Animal Ambigrams" as a title. – AdmBorkBork – 2016-01-28T16:37:45.167