Introduction
A recursive acronym is an acronym that contains or refers to itself, for example:
Fish
could be a recursive acronym for Fish is shiny hero
, notice how that also contains the acronym itself. Another example is Hi
-> Hi igloo
. Or even ppcg paints
-> ppcg paints cool galaxies pouring acid into night time stars
So basically, a sentence is a recursive acronym if the first letters of each of the words spell out the first word or words.
Challenge
Make a program that takes a string of 1 or more words separated by a space character, and outputs a recursive acronym, or an empty string if it's impossible. It is impossible to make a recursive acronym for a string like, for example, ppcg elephant
because you would start by taking the p
from ppcg
then adding that to the acronym, then taking the e
from elephant
. But now we have a contradiction, since the acronym currently spells out "pe..", which conflicts with "pp..". That's also the case with, for example, hi
. You would take the h
from hi
, but the sentence is now over and there are no more letters to spell out hi
and we are just left with h
which doesn't match hi
. (The string needs an amount of words more than or equal to the amount of letters in the acronym)
Input and output are not case sensitive
Restrictions
- Anything inputted into your program will be valid English words. But you must make sure to output valid English words too (you can use a database or just store a word for each of the 26 letters)
- Standard loopholes and default IO rules apply
Test Cases
hi igloo -> hi
ppcg paints -> (impossible)
ppcg paints cool giraffes -> ppcg
ppcg paints cool galaxies pouring acid into night time stars -> ppcgpaints
ppcg paints cool galaxies pouring acid into night time -> ppcg
ppcg questions professional pool challengers greatly -> (impossible)
I -> I
Scoring
This is code-golf, so the smallest source code in bytes wins
ppcg paints cool galaxies pouring acid into night time
would be "ppcgpaint" when made into an acronym, but the output should beppcg
even though it's only a partial match? \$\endgroup\$