Find a recursive acronym

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
7
down vote

favorite












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










share|improve this question























  • Partially related.
    – AdmBorkBork
    21 hours ago










  • What's valid English? Is gat one?
    – l4m2
    19 hours ago










  • @l4m2 Anything that's found in a dictionary, I wont be too strict about that rule
    – FireCubez
    18 hours ago






  • 1




    Q, q [kyoo] noun, plural Q's or Qs, q's or qs. the 17th letter of the English alphabet, a consonant. any spoken sound represented by the letter Q or q, as in quick, acquit, or Iraq. something having the shape of a Q.
    – l4m2
    18 hours ago






  • 2




    Also I don't think ppcg is a word in dictionary
    – l4m2
    17 hours ago














up vote
7
down vote

favorite












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










share|improve this question























  • Partially related.
    – AdmBorkBork
    21 hours ago










  • What's valid English? Is gat one?
    – l4m2
    19 hours ago










  • @l4m2 Anything that's found in a dictionary, I wont be too strict about that rule
    – FireCubez
    18 hours ago






  • 1




    Q, q [kyoo] noun, plural Q's or Qs, q's or qs. the 17th letter of the English alphabet, a consonant. any spoken sound represented by the letter Q or q, as in quick, acquit, or Iraq. something having the shape of a Q.
    – l4m2
    18 hours ago






  • 2




    Also I don't think ppcg is a word in dictionary
    – l4m2
    17 hours ago












up vote
7
down vote

favorite









up vote
7
down vote

favorite











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










share|improve this question















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







code-golf string






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 11 mins ago

























asked 22 hours ago









FireCubez

1649




1649











  • Partially related.
    – AdmBorkBork
    21 hours ago










  • What's valid English? Is gat one?
    – l4m2
    19 hours ago










  • @l4m2 Anything that's found in a dictionary, I wont be too strict about that rule
    – FireCubez
    18 hours ago






  • 1




    Q, q [kyoo] noun, plural Q's or Qs, q's or qs. the 17th letter of the English alphabet, a consonant. any spoken sound represented by the letter Q or q, as in quick, acquit, or Iraq. something having the shape of a Q.
    – l4m2
    18 hours ago






  • 2




    Also I don't think ppcg is a word in dictionary
    – l4m2
    17 hours ago
















  • Partially related.
    – AdmBorkBork
    21 hours ago










  • What's valid English? Is gat one?
    – l4m2
    19 hours ago










  • @l4m2 Anything that's found in a dictionary, I wont be too strict about that rule
    – FireCubez
    18 hours ago






  • 1




    Q, q [kyoo] noun, plural Q's or Qs, q's or qs. the 17th letter of the English alphabet, a consonant. any spoken sound represented by the letter Q or q, as in quick, acquit, or Iraq. something having the shape of a Q.
    – l4m2
    18 hours ago






  • 2




    Also I don't think ppcg is a word in dictionary
    – l4m2
    17 hours ago















Partially related.
– AdmBorkBork
21 hours ago




Partially related.
– AdmBorkBork
21 hours ago












What's valid English? Is gat one?
– l4m2
19 hours ago




What's valid English? Is gat one?
– l4m2
19 hours ago












@l4m2 Anything that's found in a dictionary, I wont be too strict about that rule
– FireCubez
18 hours ago




@l4m2 Anything that's found in a dictionary, I wont be too strict about that rule
– FireCubez
18 hours ago




1




1




Q, q [kyoo] noun, plural Q's or Qs, q's or qs. the 17th letter of the English alphabet, a consonant. any spoken sound represented by the letter Q or q, as in quick, acquit, or Iraq. something having the shape of a Q.
– l4m2
18 hours ago




Q, q [kyoo] noun, plural Q's or Qs, q's or qs. the 17th letter of the English alphabet, a consonant. any spoken sound represented by the letter Q or q, as in quick, acquit, or Iraq. something having the shape of a Q.
– l4m2
18 hours ago




2




2




Also I don't think ppcg is a word in dictionary
– l4m2
17 hours ago




Also I don't think ppcg is a word in dictionary
– l4m2
17 hours ago










13 Answers
13






active

oldest

votes

















up vote
3
down vote














Japt, 13 bytes



¸
mά
VøUÎ ©V


Try it online!






share|improve this answer






















  • 11 bytes
    – Shaggy
    20 hours ago






  • 1




    This fails on the ppcg paints cool galaxies pouring acid into night time stars test case
    – Kamil Drakari
    18 hours ago










  • here's a version that works for that test case, but it's not golfed
    – Kamil Drakari
    18 hours ago










  • My previous 13 bytes solution was correct Dx
    – Luis felipe De jesus Munoz
    16 hours ago










  • The current version just checks that the acronym contains the first word, which results in some new issues
    – Kamil Drakari
    14 hours ago

















up vote
3
down vote














05AB1E, 16 bytes



ð¡©ηʒJ®€нJηså}θJ


Try it online!






share|improve this answer


















  • 1




    Why did it change to ð¡ instead of # in your last edit? Some special test cases I'm not taking into account?
    – Kevin Cruijssen
    21 hours ago










  • @KevinCruijssen: Because # would fail for single word input outputting the input instead of an empty string.
    – Emigna
    21 hours ago










  • Ah yeah, that was it. I remember asking something similar before. I still think # should act the same as ð¡.. Is there a use-case you can think of where you want to split a string on spaces, but if it doesn't contain a space, it should remain the string (instead of the string wrapped in a list)? Other people reading this; FYI: Using # (split on space) on a string without spaces results in the string as is (i.e. "test" -> "test"). Using ð¡ (split on space) on a string without spaces results in the string wrapped in a list (i.e. "test" -> ["test"]).
    – Kevin Cruijssen
    21 hours ago











  • @KevinCruijssen: I think it's mainly due to # also being used as quit if true (which is its main function). If # returned false, you probably wouldn't want the value checked to be wrapped in a list, left on the stack.
    – Emigna
    21 hours ago






  • 1




    @KamilDrakari: Works now though.
    – Emigna
    11 hours ago

















up vote
2
down vote














Perl 6, 50 42 58 bytes





~first m:g/<<./.join.starts-with($^a),[R,] [~] .words


Try it online!



First option. I'm exploiting the fact the ord only returns the ordinal value of first letter of a string, while chrs takes a list of ords and returns a string. Or the regex from moonheart's answer is shorter :(. For reference, the previous answer was .words>>.ord.chrs instead of [~] m:g/<<./



Explanation:



~first m:g/<<./.join.starts-with($^a),[R,] [~] .words
# Anonymous code block
first # Find the first
[R,] [~] .words # Of the reverse of the triangular joined words
# That matches:
m:g/ / # Match all from the original string
<<. # Single letters after a word boundary
.join # Joined
.starts-with($^a) # And starts with the given word
~ # And stringify Nil to empty string





share|improve this answer






















  • You aren't required to output "IMPOSSIBLE" now
    – FireCubez
    21 hours ago










  • @Jo King I can do regexes, but for the life of me I can't seem to think with all the operators. I keep forgetting the x operator exists, for example :P
    – moonheart08
    16 hours ago

















up vote
1
down vote














Retina 0.8.2, 60 bytes



^
$'¶
G(w)w* ?
$1
+`^(.+)(w.*¶1 )
$1 $2
!`^(.+)(?=¶1 )


Try it online! Finds the recursive acronym, if any. Explanation:



^
$'¶


Duplicate the input.



G(w)w* ?
$1


Reduce the words on the first line to their initial letters.



+`^(.+)(w.*¶1 )
$1 $2


Insert spaces to match the original words, if possible.



!`^(.+)(?=¶1 )


Output the first line if it is a prefix of the second line.






share|improve this answer






















  • For ppcg paints, output is invalid, it should output nothing since pp only spells a portion of the first word, instead of all of it
    – FireCubez
    21 hours ago










  • @FireCubez Sorry, I was working off an older version of the question.
    – Neil
    21 hours ago

















up vote
1
down vote














Perl 6, 56 bytes





$!=[~] m:g<<.;say $! if m:g<<w+.map($_ eq $!).any


Try it online!



Previously regexes were confusing and unusable to me. Suddenly I understand them perfectly. What happened to me :P



Fulfills choice 1.






share|improve this answer




















  • Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails the ppcgpaints test, otherwise I would have suggested something like $!∈.words for the if condition
    – Jo King
    16 hours ago

















up vote
1
down vote













Rust, 155, try it online!



Selected: Problem 1: Finding acronym





type S=String;fn f(t:&str)->Sa+&b[..1])+" ";if (l+" ").contains(w.as_str())welseS::new()


Ungolfed, just a bit:



fn f(t: &str) -> String a, b


Or if we can assume that the input is all lowercase, just 130:



type S=String;fn f(l:S)->Sa+&b[..1])+" ";if (l+" ").contains(&w.as_str())welseS::new()





share|improve this answer






















  • Which of the 2 choices does this program do?
    – FireCubez
    18 hours ago










  • @FireCubez Updated.
    – Hannes Karppila
    14 hours ago

















up vote
1
down vote














Jelly, 9 bytes



Ḳµ;fZḢWƊ


A full-program printing the recursive abbreviation if it is possible.



Try it online!



How?



Ḳµ;fZḢWƊ - Main Link: list of characters
Ḳ - split at space (let's call this v)
µ - start a new monadic chain (i.e. f(v)):
- cumulative reduce v with:
; - concatenation -> [v(1), v(1);v(2), v(1);v(2);v(3); ...]
Ɗ - last three links as a monad (i.e. f(v)):
Z - transpose -> [[v(1)[1], v(2)[1], ...],[v(1)[1],v(2)[2],...],...]
Ḣ - head -> [v(1)[1], v(2)[1], ...] ... i.e. 'the potential abbreviation'
W - wrap in a list -> ['the potential abbreviation']
f - filter discard those from the left list that are not in the right list
- implicit print -- a list of length 0 prints nothing
- while a list of a single item prints that item





share|improve this answer






















  • What do you mean by "print the first word"? It needs to find the acronym if one exists, does it do that?
    – FireCubez
    14 hours ago










  • Fails for "ppcg paints cool galaxies pouring acid into not the sky", should print "ppcg paints" or "ppcgpaints"
    – FireCubez
    13 hours ago










  • Oh, I missed the adjoining words requirement :(
    – Jonathan Allan
    13 hours ago










  • Fixed it up to meet this requirement.
    – Jonathan Allan
    13 hours ago

















up vote
1
down vote













JavaScript [ES6], 64 bytes



Using the first option:



s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


Matches the initial letters to each word wrapped in parentheses, eg:



ppcgpaint
(ppcg)?(paints)?(cool)?(galaxies)?(pouring)?(acid)?(into)?(night)?(time)?


All test cases:






let f=
s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


console.log(f('hi igloo')) // hi
console.log(f('ppcg paints')) // empty string
console.log(f('ppcg paints cool giraffes')) // ppcg
console.log(f('ppcg paints cool galaxies pouring acid into night time stars')) // ppcgpaints
console.log(f('ppcg paints cool galaxies pouring acid into night time')) // ppcg
console.log(f('ppcg questions professional pool challengers greatly')) // empty string
console.log(f('I')) // I








share|improve this answer





























    up vote
    1
    down vote













    Haskell, 51 48 bytes



    Edit: -3 bytes thanks to @xnor.



    (w->[r|p<-scanl1(++)w,map(!!0)w==p,r<-p]).words


    Finds acronym.



    Try it online!



    w-> .words -- let 'w' be the input list split into words
    p<-scanl1(++)w -- loop 'p' through the list starting with the first word
    -- and appending the next words one by one, e.g.
    -- "Fish","is","shiny","hero" -> "Fish","Fishis","Fishisshiny","Fishisshinyhero"
    ,map(!!0)w==p -- if the word made out of the first characters of the
    -- words of 'w' equal 'p'
    [r| r<-p] -- return the letters of 'p' - if the check before
    -- never evaluates to True then no letters, i.e. the
    -- the empty string is returned





    share|improve this answer






















    • Since you're not using x, composing (w-> ...).words would be shorter.
      – xnor
      10 hours ago


















    up vote
    0
    down vote














    Python 2, 106 bytes



    First option - finding recursive acronym.

    Returns result in list.





    I=input().split()
    print[' '.join(I[:i])for i in range(1,-~len(I))if[j[0]for j in I]==list(''.join(I[:i]))]


    Try it online!




    Python 2, 120 bytes



    First option - finding recursive acronym.





    def F(I,a=,r=''):
    for j in I.split():
    a+=j,
    if list(''.join(a))==[i[0]for i in I.split()]:r=' '.join(a)
    return r


    Try it online!






    share|improve this answer






















    • You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
      – FireCubez
      21 hours ago










    • Single letters like 'I' don't work, it should output that single letter
      – FireCubez
      21 hours ago










    • @FireCubez fixed
      – Dead Possum
      20 hours ago

















    up vote
    0
    down vote













    Javascript, 71 bytes



    Approach 1



    l=s=>p=s.split(' ');k=p.reduce((r,x)=>r+x[0],'');return k==p[0]?k:''


    Ungolfed:



    l=s=>
    p = s.split(' ');
    k = p.reduce((r,x)=>r+x[0],'');
    return k==p[0] ? k : '';



    • Split the string by space.

    • Create new string by taking first character from each word.

    • Compare it with the first word.





    share|improve this answer








    New contributor




    alpheus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      up vote
      0
      down vote














      K (ngn/k), 40 bytes



      First option:



      $[1=#:x;x;$[(*:t)~,/*:'t:" "x;*:t;`]]


      Try it online!






      share|improve this answer






















      • Which of the 2 options does this work on?
        – FireCubez
        18 hours ago










      • The first, outputs acronym from string input. I'll edit my post to clarify
        – Thaufeki
        18 hours ago


















      up vote
      0
      down vote














      JavaScript (Node.js), 70 bytes





      s=>(s.replace(/w+/g,x=>w+=x[0]+' ?',w='^'),s.match(w+'\b')||[''])[0]


      Try it online!






      share|improve this answer






















        Your Answer




        StackExchange.ifUsing("editor", function ()
        return StackExchange.using("mathjaxEditing", function ()
        StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
        StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
        );
        );
        , "mathjax-editing");

        StackExchange.ifUsing("editor", function () improve this answer








        edited 16 hours ago

























        answered 21 hours ago









        Luis felipe De jesus Munoz

        3,41511049




        3,41511049











        • 11 bytes
          – Shaggy
          20 hours ago






        • 1




          This fails on the ppcg paints cool galaxies pouring acid into night time stars test case
          – Kamil Drakari
          18 hours ago










        • here's a version that works for that test case, but it's not golfed
          – Kamil Drakari
          18 hours ago










        • My previous 13 bytes solution was correct Dx
          – Luis felipe De jesus Munoz
          16 hours ago










        • The current version just checks that the acronym contains the first word, which results in some new issues
          – Kamil Drakari
          14 hours ago









        share|improve this answer


















        • 1




          Why did it change to ð¡ instead of # in your last edit? Some special test cases I'm not taking into account?
          – Kevin Cruijssen
          21 hours ago










        • @KevinCruijssen: Because # would fail for single word input outputting the input instead of an empty string.
          – Emigna
          21 hours ago










        • Ah yeah, that was it. I remember asking something similar before. I still think # should act the same as ð¡.. Is there a use-case you can think of where you want to split a string on spaces, but if it doesn't contain a space, it should remain the string (instead of the string wrapped in a list)? Other people reading this; FYI: Using # (split on space) on a string without spaces results in the string as is (i.e. "test" -> "test"). Using ð¡ (split on space) on a string without spaces results in the string wrapped in a list (i.e. "test" -> ["test"]).
          – Kevin Cruijssen
          21 hours ago











        • @KevinCruijssen: I think it's mainly due to # also being used as quit if true (which is its main function). If # returned false, you probably wouldn't want the value checked to be wrapped in a list, left on the stack.
          – Emigna
          21 hours ago






        • 1




          @KamilDrakari: Works now though.
          – Emigna
          11 hours ago














        up vote
        3
        down vote














        05AB1E, 16 bytes



        ð¡©ηʒJ®€нJηså}θJ


        Try it online!






        share|improve this answer


















        • 1




          Why did it change to ð¡ instead of # in your last edit? Some special test cases I'm not taking into account?
          – Kevin Cruijssen
          21 hours ago










        • @KevinCruijssen: Because # would fail for single word input outputting the input instead of an empty string.
          – Emigna
          21 hours ago










        • Ah yeah, that was it. I remember asking something similar before. I still think # should act the same as ð¡.. Is there a use-case you can think of where you want to split a string on spaces, but if it doesn't contain a space, it should remain the string (instead of the string wrapped in a list)? Other people reading this; FYI: Using # (split on space) on a string without spaces results in the string as is (i.e. "test" -> "test"). Using ð¡ (split on space) on a string without spaces results in the string wrapped in a list (i.e. "test" -> ["test"]).
          – Kevin Cruijssen
          21 hours ago











        • @KevinCruijssen: I think it's mainly due to # also being used as quit if true (which is its main function). If # returned false, you probably wouldn't want the value checked to be wrapped in a list, left on the stack.
          – Emigna
          21 hours ago






        • 1




          @KamilDrakari: Works now though.
          – Emigna
          11 hours ago












        up vote
        3
        down vote










        up vote
        3
        down vote










        05AB1E, 16 bytes



        ð¡©ηʒJ®€нJηså}θJ


        Try it online!






        share|improve this answer















        05AB1E, 16 bytes



        ð¡©ηʒJ®€нJηså}θJ


        Try it online!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 11 hours ago

























        answered 21 hours ago









        Emigna

        44k431133




        44k431133







        • 1




          Why did it change to ð¡ instead of # in your last edit? Some special test cases I'm not taking into account?
          – Kevin Cruijssen
          21 hours ago










        • @KevinCruijssen: Because # would fail for single word input outputting the input instead of an empty string.
          – Emigna
          21 hours ago










        • Ah yeah, that was it. I remember asking something similar before. I still think # should act the same as ð¡.. Is there a use-case you can think of where you want to split a string on spaces, but if it doesn't contain a space, it should remain the string (instead of the string wrapped in a list)? Other people reading this; FYI: Using # (split on space) on a string without spaces results in the string as is (i.e. "test" -> "test"). Using ð¡ (split on space) on a string without spaces results in the string wrapped in a list (i.e. "test" -> ["test"]).
          – Kevin Cruijssen
          21 hours ago











        • @KevinCruijssen: I think it's mainly due to # also being used as quit if true (which is its main function). If # returned false, you probably wouldn't want the value checked to be wrapped in a list, left on the stack.
          – Emigna
          21 hours ago






        • 1




          @KamilDrakari: Works now though.
          – Emigna
          11 hours ago












        • 1




          Why did it change to ð¡ instead of # in your last edit? Some special test cases I'm not taking into account?
          – Kevin Cruijssen
          21 hours ago










        • @KevinCruijssen: Because # would fail for single word input outputting the input instead of an empty string.
          – Emigna
          21 hours ago










        • Ah yeah, that was it. I remember asking something similar before. I still think # should act the same as ð¡.. Is there a use-case you can think of where you want to split a string on spaces, but if it doesn't contain a space, it should remain the string (instead of the string wrapped in a list)? Other people reading this; FYI: Using # (split on space) on a string without spaces results in the string as is (i.e. "test" -> "test"). Using ð¡ (split on space) on a string without spaces results in the string wrapped in a list (i.e. "test" -> ["test"]).
          – Kevin Cruijssen
          21 hours ago











        • @KevinCruijssen: I think it's mainly due to # also being used as quit if true (which is its main function). If # returned false, you probably wouldn't want the value checked to be wrapped in a list, left on the stack.
          – Emigna
          21 hours ago






        • 1




          @KamilDrakari: Works now though.
          – Emigna
          11 hours ago







        1




        1




        Why did it change to ð¡ instead of # in your last edit? Some special test cases I'm not taking into account?
        – Kevin Cruijssen
        21 hours ago




        Why did it change to ð¡ instead of # in your last edit? Some special test cases I'm not taking into account?
        – Kevin Cruijssen
        21 hours ago












        @KevinCruijssen: Because # would fail for single word input outputting the input instead of an empty string.
        – Emigna
        21 hours ago




        @KevinCruijssen: Because # would fail for single word input outputting the input instead of an empty string.
        – Emigna
        21 hours ago












        Ah yeah, that was it. I remember asking something similar before. I still think # should act the same as ð¡.. Is there a use-case you can think of where you want to split a string on spaces, but if it doesn't contain a space, it should remain the string (instead of the string wrapped in a list)? Other people reading this; FYI: Using # (split on space) on a string without spaces results in the string as is (i.e. "test" -> "test"). Using ð¡ (split on space) on a string without spaces results in the string wrapped in a list (i.e. "test" -> ["test"]).
        – Kevin Cruijssen
        21 hours ago





        Ah yeah, that was it. I remember asking something similar before. I still think # should act the same as ð¡.. Is there a use-case you can think of where you want to split a string on spaces, but if it doesn't contain a space, it should remain the string (instead of the string wrapped in a list)? Other people reading this; FYI: Using # (split on space) on a string without spaces results in the string as is (i.e. "test" -> "test"). Using ð¡ (split on space) on a string without spaces results in the string wrapped in a list (i.e. "test" -> ["test"]).
        – Kevin Cruijssen
        21 hours ago













        @KevinCruijssen: I think it's mainly due to # also being used as quit if true (which is its main function). If # returned false, you probably wouldn't want the value checked to be wrapped in a list, left on the stack.
        – Emigna
        21 hours ago




        @KevinCruijssen: I think it's mainly due to # also being used as quit if true (which is its main function). If # returned false, you probably wouldn't want the value checked to be wrapped in a list, left on the stack.
        – Emigna
        21 hours ago




        1




        1




        @KamilDrakari: Works now though.
        – Emigna
        11 hours ago




        @KamilDrakari: Works now though.
        – Emigna
        11 hours ago










        up vote
        2
        down vote














        Perl 6, 50 42 58 bytes





        ~first m:g/<<./.join.starts-with($^a),[R,] [~] .words


        Try it online!



        First option. I'm exploiting the fact the ord only returns the ordinal value of first letter of a string, while chrs takes a list of ords and returns a string. Or the regex from moonheart's answer is shorter :(. For reference, the previous answer was .words>>.ord.chrs instead of [~] m:g/<<./



        Explanation:



        ~first m:g/<<./.join.starts-with($^a),[R,] [~] .words
        # Anonymous code block
        first # Find the first
        [R,] [~] .words # Of the reverse of the triangular joined words
        # That matches:
        m:g/ / # Match all from the original string
        <<. # Single letters after a word boundary
        .join # Joined
        .starts-with($^a) # And starts with the given word
        ~ # And stringify Nil to empty string





        share|improve this answer






















        • You aren't required to output "IMPOSSIBLE" now
          – FireCubez
          21 hours ago










        • @Jo King I can do regexes, but for the life of me I can't seem to think with all the operators. I keep forgetting the x operator exists, for example :P
          – moonheart08
          16 hours ago














        up vote
        2
        down vote














        Perl 6, 50 42 58 bytes





        ~first m:g/<<./.join.starts-with($^a),[R,] [~] .words


        Try it online!



        First option. I'm exploiting the fact the ord only returns the ordinal value of first letter of a string, while chrs takes a list of ords and returns a string. Or the regex from moonheart's answer is shorter :(. For reference, the previous answer was .words>>.ord.chrs instead of [~] m:g/<<./



        Explanation:



        ~first m:g/<<./.join.starts-with($^a),[R,] [~] .words
        # Anonymous code block
        first # Find the first
        [R,] [~] .words # Of the reverse of the triangular joined words
        # That matches:
        m:g/ / # Match all from the original string
        <<. # Single letters after a word boundary
        .join # Joined
        .starts-with($^a) # And starts with the given word
        ~ # And stringify Nil to empty string





        share|improve this answer






















        • You aren't required to output "IMPOSSIBLE" now
          – FireCubez
          21 hours ago










        • @Jo King I can do regexes, but for the life of me I can't seem to think with all the operators. I keep forgetting the x operator exists, for example :P
          – moonheart08
          16 hours ago












        up vote
        2
        down vote










        up vote
        2
        down vote










        Perl 6, 50 42 58 bytes





        ~first m:g/<<./.join.starts-with($^a),[R,] [~] .words


        Try it online!



        First option. I'm exploiting the fact the ord only returns the ordinal value of first letter of a string, while chrs takes a list of ords and returns a string. Or the regex from moonheart's answer is shorter :(. For reference, the previous answer was .words>>.ord.chrs instead of [~] m:g/<<./



        Explanation:



        ~first m:g/<<./.join.starts-with($^a),[R,] [~] .words
        # Anonymous code block
        first # Find the first
        [R,] [~] .words # Of the reverse of the triangular joined words
        # That matches:
        m:g/ / # Match all from the original string
        <<. # Single letters after a word boundary
        .join # Joined
        .starts-with($^a) # And starts with the given word
        ~ # And stringify Nil to empty string





        share|improve this answer















        Perl 6, 50 42 58 bytes





        ~first m:g/<<./.join.starts-with($^a),[R,] [~] .words


        Try it online!



        First option. I'm exploiting the fact the ord only returns the ordinal value of first letter of a string, while chrs takes a list of ords and returns a string. Or the regex from moonheart's answer is shorter :(. For reference, the previous answer was .words>>.ord.chrs instead of [~] m:g/<<./



        Explanation:



        ~first m:g/<<./.join.starts-with($^a),[R,] [~] .words
        # Anonymous code block
        first # Find the first
        [R,] [~] .words # Of the reverse of the triangular joined words
        # That matches:
        m:g/ / # Match all from the original string
        <<. # Single letters after a word boundary
        .join # Joined
        .starts-with($^a) # And starts with the given word
        ~ # And stringify Nil to empty string






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 12 mins ago

























        answered 21 hours ago









        Jo King

        17.9k24198




        17.9k24198











        • You aren't required to output "IMPOSSIBLE" now
          – FireCubez
          21 hours ago










        • @Jo King I can do regexes, but for the life of me I can't seem to think with all the operators. I keep forgetting the x operator exists, for example :P
          – moonheart08
          16 hours ago
















        • You aren't required to output "IMPOSSIBLE" now
          – FireCubez
          21 hours ago










        • @Jo King I can do regexes, but for the life of me I can't seem to think with all the operators. I keep forgetting the x operator exists, for example :P
          – moonheart08
          16 hours ago















        You aren't required to output "IMPOSSIBLE" now
        – FireCubez
        21 hours ago




        You aren't required to output "IMPOSSIBLE" now
        – FireCubez
        21 hours ago












        @Jo King I can do regexes, but for the life of me I can't seem to think with all the operators. I keep forgetting the x operator exists, for example :P
        – moonheart08
        16 hours ago




        @Jo King I can do regexes, but for the life of me I can't seem to think with all the operators. I keep forgetting the x operator exists, for example :P
        – moonheart08
        16 hours ago










        up vote
        1
        down vote














        Retina 0.8.2, 60 bytes



        ^
        $'¶
        G(w)w* ?
        $1
        +`^(.+)(w.*¶1 )
        $1 $2
        !`^(.+)(?=¶1 )


        Try it online! Finds the recursive acronym, if any. Explanation:



        ^
        $'¶


        Duplicate the input.



        G(w)w* ?
        $1


        Reduce the words on the first line to their initial letters.



        +`^(.+)(w.*¶1 )
        $1 $2


        Insert spaces to match the original words, if possible.



        !`^(.+)(?=¶1 )


        Output the first line if it is a prefix of the second line.






        share|improve this answer






















        • For ppcg paints, output is invalid, it should output nothing since pp only spells a portion of the first word, instead of all of it
          – FireCubez
          21 hours ago










        • @FireCubez Sorry, I was working off an older version of the question.
          – Neil
          21 hours ago














        up vote
        1
        down vote














        Retina 0.8.2, 60 bytes



        ^
        $'¶
        G(w)w* ?
        $1
        +`^(.+)(w.*¶1 )
        $1 $2
        !`^(.+)(?=¶1 )


        Try it online! Finds the recursive acronym, if any. Explanation:



        ^
        $'¶


        Duplicate the input.



        G(w)w* ?
        $1


        Reduce the words on the first line to their initial letters.



        +`^(.+)(w.*¶1 )
        $1 $2


        Insert spaces to match the original words, if possible.



        !`^(.+)(?=¶1 )


        Output the first line if it is a prefix of the second line.






        share|improve this answer






















        • For ppcg paints, output is invalid, it should output nothing since pp only spells a portion of the first word, instead of all of it
          – FireCubez
          21 hours ago










        • @FireCubez Sorry, I was working off an older version of the question.
          – Neil
          21 hours ago












        up vote
        1
        down vote










        up vote
        1
        down vote










        Retina 0.8.2, 60 bytes



        ^
        $'¶
        G(w)w* ?
        $1
        +`^(.+)(w.*¶1 )
        $1 $2
        !`^(.+)(?=¶1 )


        Try it online! Finds the recursive acronym, if any. Explanation:



        ^
        $'¶


        Duplicate the input.



        G(w)w* ?
        $1


        Reduce the words on the first line to their initial letters.



        +`^(.+)(w.*¶1 )
        $1 $2


        Insert spaces to match the original words, if possible.



        !`^(.+)(?=¶1 )


        Output the first line if it is a prefix of the second line.






        share|improve this answer















        Retina 0.8.2, 60 bytes



        ^
        $'¶
        G(w)w* ?
        $1
        +`^(.+)(w.*¶1 )
        $1 $2
        !`^(.+)(?=¶1 )


        Try it online! Finds the recursive acronym, if any. Explanation:



        ^
        $'¶


        Duplicate the input.



        G(w)w* ?
        $1


        Reduce the words on the first line to their initial letters.



        +`^(.+)(w.*¶1 )
        $1 $2


        Insert spaces to match the original words, if possible.



        !`^(.+)(?=¶1 )


        Output the first line if it is a prefix of the second line.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 21 hours ago

























        answered 21 hours ago









        Neil

        77k744173




        77k744173











        • For ppcg paints, output is invalid, it should output nothing since pp only spells a portion of the first word, instead of all of it
          – FireCubez
          21 hours ago










        • @FireCubez Sorry, I was working off an older version of the question.
          – Neil
          21 hours ago
















        • For ppcg paints, output is invalid, it should output nothing since pp only spells a portion of the first word, instead of all of it
          – FireCubez
          21 hours ago










        • @FireCubez Sorry, I was working off an older version of the question.
          – Neil
          21 hours ago















        For ppcg paints, output is invalid, it should output nothing since pp only spells a portion of the first word, instead of all of it
        – FireCubez
        21 hours ago




        For ppcg paints, output is invalid, it should output nothing since pp only spells a portion of the first word, instead of all of it
        – FireCubez
        21 hours ago












        @FireCubez Sorry, I was working off an older version of the question.
        – Neil
        21 hours ago




        @FireCubez Sorry, I was working off an older version of the question.
        – Neil
        21 hours ago










        up vote
        1
        down vote














        Perl 6, 56 bytes





        $!=[~] m:g<<.;say $! if m:g<<w+.map($_ eq $!).any


        Try it online!



        Previously regexes were confusing and unusable to me. Suddenly I understand them perfectly. What happened to me :P



        Fulfills choice 1.






        share|improve this answer




















        • Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails the ppcgpaints test, otherwise I would have suggested something like $!∈.words for the if condition
          – Jo King
          16 hours ago














        up vote
        1
        down vote














        Perl 6, 56 bytes





        $!=[~] m:g<<.;say $! if m:g<<w+.map($_ eq $!).any


        Try it online!



        Previously regexes were confusing and unusable to me. Suddenly I understand them perfectly. What happened to me :P



        Fulfills choice 1.






        share|improve this answer




















        • Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails the ppcgpaints test, otherwise I would have suggested something like $!∈.words for the if condition
          – Jo King
          16 hours ago












        up vote
        1
        down vote










        up vote
        1
        down vote










        Perl 6, 56 bytes





        $!=[~] m:g<<.;say $! if m:g<<w+.map($_ eq $!).any


        Try it online!



        Previously regexes were confusing and unusable to me. Suddenly I understand them perfectly. What happened to me :P



        Fulfills choice 1.






        share|improve this answer













        Perl 6, 56 bytes





        $!=[~] m:g<<.;say $! if m:g<<w+.map($_ eq $!).any


        Try it online!



        Previously regexes were confusing and unusable to me. Suddenly I understand them perfectly. What happened to me :P



        Fulfills choice 1.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 18 hours ago









        moonheart08

        59210




        59210











        • Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails the ppcgpaints test, otherwise I would have suggested something like $!∈.words for the if condition
          – Jo King
          16 hours ago
















        • Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails the ppcgpaints test, otherwise I would have suggested something like $!∈.words for the if condition
          – Jo King
          16 hours ago















        Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails the ppcgpaints test, otherwise I would have suggested something like $!∈.words for the if condition
        – Jo King
        16 hours ago




        Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails the ppcgpaints test, otherwise I would have suggested something like $!∈.words for the if condition
        – Jo King
        16 hours ago










        up vote
        1
        down vote













        Rust, 155, try it online!



        Selected: Problem 1: Finding acronym





        type S=String;fn f(t:&str)->Sa+&b[..1])+" ";if (l+" ").contains(w.as_str())welseS::new()


        Ungolfed, just a bit:



        fn f(t: &str) -> String a, b


        Or if we can assume that the input is all lowercase, just 130:



        type S=String;fn f(l:S)->Sa+&b[..1])+" ";if (l+" ").contains(&w.as_str())welseS::new()





        share|improve this answer






















        • Which of the 2 choices does this program do?
          – FireCubez
          18 hours ago










        • @FireCubez Updated.
          – Hannes Karppila
          14 hours ago














        up vote
        1
        down vote













        Rust, 155, try it online!



        Selected: Problem 1: Finding acronym





        type S=String;fn f(t:&str)->Sa+&b[..1])+" ";if (l+" ").contains(w.as_str())welseS::new()


        Ungolfed, just a bit:



        fn f(t: &str) -> String a, b


        Or if we can assume that the input is all lowercase, just 130:



        type S=String;fn f(l:S)->Sa+&b[..1])+" ";if (l+" ").contains(&w.as_str())welseS::new()





        share|improve this answer






















        • Which of the 2 choices does this program do?
          – FireCubez
          18 hours ago










        • @FireCubez Updated.
          – Hannes Karppila
          14 hours ago












        up vote
        1
        down vote










        up vote
        1
        down vote









        Rust, 155, try it online!



        Selected: Problem 1: Finding acronym





        type S=String;fn f(t:&str)->Sa+&b[..1])+" ";if (l+" ").contains(w.as_str())welseS::new()


        Ungolfed, just a bit:



        fn f(t: &str) -> String a, b


        Or if we can assume that the input is all lowercase, just 130:



        type S=String;fn f(l:S)->Sa+&b[..1])+" ";if (l+" ").contains(&w.as_str())welseS::new()





        share|improve this answer














        Rust, 155, try it online!



        Selected: Problem 1: Finding acronym





        type S=String;fn f(t:&str)->Sa+&b[..1])+" ";if (l+" ").contains(w.as_str())welseS::new()


        Ungolfed, just a bit:



        fn f(t: &str) -> String a, b


        Or if we can assume that the input is all lowercase, just 130:



        type S=String;fn f(l:S)->Sa+&b[..1])+" ";if (l+" ").contains(&w.as_str())welseS::new()






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 14 hours ago

























        answered 19 hours ago









        Hannes Karppila

        2,00421136




        2,00421136











        • Which of the 2 choices does this program do?
          – FireCubez
          18 hours ago










        • @FireCubez Updated.
          – Hannes Karppila
          14 hours ago
















        • Which of the 2 choices does this program do?
          – FireCubez
          18 hours ago










        • @FireCubez Updated.
          – Hannes Karppila
          14 hours ago















        Which of the 2 choices does this program do?
        – FireCubez
        18 hours ago




        Which of the 2 choices does this program do?
        – FireCubez
        18 hours ago












        @FireCubez Updated.
        – Hannes Karppila
        14 hours ago




        @FireCubez Updated.
        – Hannes Karppila
        14 hours ago










        up vote
        1
        down vote














        Jelly, 9 bytes



        Ḳµ;fZḢWƊ


        A full-program printing the recursive abbreviation if it is possible.



        Try it online!



        How?



        Ḳµ;fZḢWƊ - Main Link: list of characters
        Ḳ - split at space (let's call this v)
        µ - start a new monadic chain (i.e. f(v)):
        - cumulative reduce v with:
        ; - concatenation -> [v(1), v(1);v(2), v(1);v(2);v(3); ...]
        Ɗ - last three links as a monad (i.e. f(v)):
        Z - transpose -> [[v(1)[1], v(2)[1], ...],[v(1)[1],v(2)[2],...],...]
        Ḣ - head -> [v(1)[1], v(2)[1], ...] ... i.e. 'the potential abbreviation'
        W - wrap in a list -> ['the potential abbreviation']
        f - filter discard those from the left list that are not in the right list
        - implicit print -- a list of length 0 prints nothing
        - while a list of a single item prints that item





        share|improve this answer






















        • What do you mean by "print the first word"? It needs to find the acronym if one exists, does it do that?
          – FireCubez
          14 hours ago










        • Fails for "ppcg paints cool galaxies pouring acid into not the sky", should print "ppcg paints" or "ppcgpaints"
          – FireCubez
          13 hours ago










        • Oh, I missed the adjoining words requirement :(
          – Jonathan Allan
          13 hours ago










        • Fixed it up to meet this requirement.
          – Jonathan Allan
          13 hours ago














        up vote
        1
        down vote














        Jelly, 9 bytes



        Ḳµ;fZḢWƊ


        A full-program printing the recursive abbreviation if it is possible.



        Try it online!



        How?



        Ḳµ;fZḢWƊ - Main Link: list of characters
        Ḳ - split at space (let's call this v)
        µ - start a new monadic chain (i.e. f(v)):
        - cumulative reduce v with:
        ; - concatenation -> [v(1), v(1);v(2), v(1);v(2);v(3); ...]
        Ɗ - last three links as a monad (i.e. f(v)):
        Z - transpose -> [[v(1)[1], v(2)[1], ...],[v(1)[1],v(2)[2],...],...]
        Ḣ - head -> [v(1)[1], v(2)[1], ...] ... i.e. 'the potential abbreviation'
        W - wrap in a list -> ['the potential abbreviation']
        f - filter discard those from the left list that are not in the right list
        - implicit print -- a list of length 0 prints nothing
        - while a list of a single item prints that item





        share|improve this answer






















        • What do you mean by "print the first word"? It needs to find the acronym if one exists, does it do that?
          – FireCubez
          14 hours ago










        • Fails for "ppcg paints cool galaxies pouring acid into not the sky", should print "ppcg paints" or "ppcgpaints"
          – FireCubez
          13 hours ago










        • Oh, I missed the adjoining words requirement :(
          – Jonathan Allan
          13 hours ago










        • Fixed it up to meet this requirement.
          – Jonathan Allan
          13 hours ago












        up vote
        1
        down vote










        up vote
        1
        down vote










        Jelly, 9 bytes



        Ḳµ;fZḢWƊ


        A full-program printing the recursive abbreviation if it is possible.



        Try it online!



        How?



        Ḳµ;fZḢWƊ - Main Link: list of characters
        Ḳ - split at space (let's call this v)
        µ - start a new monadic chain (i.e. f(v)):
        - cumulative reduce v with:
        ; - concatenation -> [v(1), v(1);v(2), v(1);v(2);v(3); ...]
        Ɗ - last three links as a monad (i.e. f(v)):
        Z - transpose -> [[v(1)[1], v(2)[1], ...],[v(1)[1],v(2)[2],...],...]
        Ḣ - head -> [v(1)[1], v(2)[1], ...] ... i.e. 'the potential abbreviation'
        W - wrap in a list -> ['the potential abbreviation']
        f - filter discard those from the left list that are not in the right list
        - implicit print -- a list of length 0 prints nothing
        - while a list of a single item prints that item





        share|improve this answer















        Jelly, 9 bytes



        Ḳµ;fZḢWƊ


        A full-program printing the recursive abbreviation if it is possible.



        Try it online!



        How?



        Ḳµ;fZḢWƊ - Main Link: list of characters
        Ḳ - split at space (let's call this v)
        µ - start a new monadic chain (i.e. f(v)):
        - cumulative reduce v with:
        ; - concatenation -> [v(1), v(1);v(2), v(1);v(2);v(3); ...]
        Ɗ - last three links as a monad (i.e. f(v)):
        Z - transpose -> [[v(1)[1], v(2)[1], ...],[v(1)[1],v(2)[2],...],...]
        Ḣ - head -> [v(1)[1], v(2)[1], ...] ... i.e. 'the potential abbreviation'
        W - wrap in a list -> ['the potential abbreviation']
        f - filter discard those from the left list that are not in the right list
        - implicit print -- a list of length 0 prints nothing
        - while a list of a single item prints that item






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 13 hours ago

























        answered 15 hours ago









        Jonathan Allan

        49.5k534163




        49.5k534163











        • What do you mean by "print the first word"? It needs to find the acronym if one exists, does it do that?
          – FireCubez
          14 hours ago










        • Fails for "ppcg paints cool galaxies pouring acid into not the sky", should print "ppcg paints" or "ppcgpaints"
          – FireCubez
          13 hours ago










        • Oh, I missed the adjoining words requirement :(
          – Jonathan Allan
          13 hours ago










        • Fixed it up to meet this requirement.
          – Jonathan Allan
          13 hours ago
















        • What do you mean by "print the first word"? It needs to find the acronym if one exists, does it do that?
          – FireCubez
          14 hours ago










        • Fails for "ppcg paints cool galaxies pouring acid into not the sky", should print "ppcg paints" or "ppcgpaints"
          – FireCubez
          13 hours ago










        • Oh, I missed the adjoining words requirement :(
          – Jonathan Allan
          13 hours ago










        • Fixed it up to meet this requirement.
          – Jonathan Allan
          13 hours ago















        What do you mean by "print the first word"? It needs to find the acronym if one exists, does it do that?
        – FireCubez
        14 hours ago




        What do you mean by "print the first word"? It needs to find the acronym if one exists, does it do that?
        – FireCubez
        14 hours ago












        Fails for "ppcg paints cool galaxies pouring acid into not the sky", should print "ppcg paints" or "ppcgpaints"
        – FireCubez
        13 hours ago




        Fails for "ppcg paints cool galaxies pouring acid into not the sky", should print "ppcg paints" or "ppcgpaints"
        – FireCubez
        13 hours ago












        Oh, I missed the adjoining words requirement :(
        – Jonathan Allan
        13 hours ago




        Oh, I missed the adjoining words requirement :(
        – Jonathan Allan
        13 hours ago












        Fixed it up to meet this requirement.
        – Jonathan Allan
        13 hours ago




        Fixed it up to meet this requirement.
        – Jonathan Allan
        13 hours ago










        up vote
        1
        down vote













        JavaScript [ES6], 64 bytes



        Using the first option:



        s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


        Matches the initial letters to each word wrapped in parentheses, eg:



        ppcgpaint
        (ppcg)?(paints)?(cool)?(galaxies)?(pouring)?(acid)?(into)?(night)?(time)?


        All test cases:






        let f=
        s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


        console.log(f('hi igloo')) // hi
        console.log(f('ppcg paints')) // empty string
        console.log(f('ppcg paints cool giraffes')) // ppcg
        console.log(f('ppcg paints cool galaxies pouring acid into night time stars')) // ppcgpaints
        console.log(f('ppcg paints cool galaxies pouring acid into night time')) // ppcg
        console.log(f('ppcg questions professional pool challengers greatly')) // empty string
        console.log(f('I')) // I








        share|improve this answer


























          up vote
          1
          down vote













          JavaScript [ES6], 64 bytes



          Using the first option:



          s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


          Matches the initial letters to each word wrapped in parentheses, eg:



          ppcgpaint
          (ppcg)?(paints)?(cool)?(galaxies)?(pouring)?(acid)?(into)?(night)?(time)?


          All test cases:






          let f=
          s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


          console.log(f('hi igloo')) // hi
          console.log(f('ppcg paints')) // empty string
          console.log(f('ppcg paints cool giraffes')) // ppcg
          console.log(f('ppcg paints cool galaxies pouring acid into night time stars')) // ppcgpaints
          console.log(f('ppcg paints cool galaxies pouring acid into night time')) // ppcg
          console.log(f('ppcg questions professional pool challengers greatly')) // empty string
          console.log(f('I')) // I








          share|improve this answer
























            up vote
            1
            down vote










            up vote
            1
            down vote









            JavaScript [ES6], 64 bytes



            Using the first option:



            s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


            Matches the initial letters to each word wrapped in parentheses, eg:



            ppcgpaint
            (ppcg)?(paints)?(cool)?(galaxies)?(pouring)?(acid)?(into)?(night)?(time)?


            All test cases:






            let f=
            s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


            console.log(f('hi igloo')) // hi
            console.log(f('ppcg paints')) // empty string
            console.log(f('ppcg paints cool giraffes')) // ppcg
            console.log(f('ppcg paints cool galaxies pouring acid into night time stars')) // ppcgpaints
            console.log(f('ppcg paints cool galaxies pouring acid into night time')) // ppcg
            console.log(f('ppcg questions professional pool challengers greatly')) // empty string
            console.log(f('I')) // I








            share|improve this answer














            JavaScript [ES6], 64 bytes



            Using the first option:



            s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


            Matches the initial letters to each word wrapped in parentheses, eg:



            ppcgpaint
            (ppcg)?(paints)?(cool)?(galaxies)?(pouring)?(acid)?(into)?(night)?(time)?


            All test cases:






            let f=
            s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


            console.log(f('hi igloo')) // hi
            console.log(f('ppcg paints')) // empty string
            console.log(f('ppcg paints cool giraffes')) // ppcg
            console.log(f('ppcg paints cool galaxies pouring acid into night time stars')) // ppcgpaints
            console.log(f('ppcg paints cool galaxies pouring acid into night time')) // ppcg
            console.log(f('ppcg questions professional pool challengers greatly')) // empty string
            console.log(f('I')) // I








            let f=
            s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


            console.log(f('hi igloo')) // hi
            console.log(f('ppcg paints')) // empty string
            console.log(f('ppcg paints cool giraffes')) // ppcg
            console.log(f('ppcg paints cool galaxies pouring acid into night time stars')) // ppcgpaints
            console.log(f('ppcg paints cool galaxies pouring acid into night time')) // ppcg
            console.log(f('ppcg questions professional pool challengers greatly')) // empty string
            console.log(f('I')) // I





            let f=
            s=>s.split` `.map(w=>t+=w[d+=`($w)?`,0],t=d='')&&t.match(d)[0]


            console.log(f('hi igloo')) // hi
            console.log(f('ppcg paints')) // empty string
            console.log(f('ppcg paints cool giraffes')) // ppcg
            console.log(f('ppcg paints cool galaxies pouring acid into night time stars')) // ppcgpaints
            console.log(f('ppcg paints cool galaxies pouring acid into night time')) // ppcg
            console.log(f('ppcg questions professional pool challengers greatly')) // empty string
            console.log(f('I')) // I






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 10 hours ago

























            answered 10 hours ago









            Rick Hitchcock

            2,421515




            2,421515




















                up vote
                1
                down vote













                Haskell, 51 48 bytes



                Edit: -3 bytes thanks to @xnor.



                (w->[r|p<-scanl1(++)w,map(!!0)w==p,r<-p]).words


                Finds acronym.



                Try it online!



                w-> .words -- let 'w' be the input list split into words
                p<-scanl1(++)w -- loop 'p' through the list starting with the first word
                -- and appending the next words one by one, e.g.
                -- "Fish","is","shiny","hero" -> "Fish","Fishis","Fishisshiny","Fishisshinyhero"
                ,map(!!0)w==p -- if the word made out of the first characters of the
                -- words of 'w' equal 'p'
                [r| r<-p] -- return the letters of 'p' - if the check before
                -- never evaluates to True then no letters, i.e. the
                -- the empty string is returned





                share|improve this answer






















                • Since you're not using x, composing (w-> ...).words would be shorter.
                  – xnor
                  10 hours ago















                up vote
                1
                down vote













                Haskell, 51 48 bytes



                Edit: -3 bytes thanks to @xnor.



                (w->[r|p<-scanl1(++)w,map(!!0)w==p,r<-p]).words


                Finds acronym.



                Try it online!



                w-> .words -- let 'w' be the input list split into words
                p<-scanl1(++)w -- loop 'p' through the list starting with the first word
                -- and appending the next words one by one, e.g.
                -- "Fish","is","shiny","hero" -> "Fish","Fishis","Fishisshiny","Fishisshinyhero"
                ,map(!!0)w==p -- if the word made out of the first characters of the
                -- words of 'w' equal 'p'
                [r| r<-p] -- return the letters of 'p' - if the check before
                -- never evaluates to True then no letters, i.e. the
                -- the empty string is returned





                share|improve this answer






















                • Since you're not using x, composing (w-> ...).words would be shorter.
                  – xnor
                  10 hours ago













                up vote
                1
                down vote










                up vote
                1
                down vote









                Haskell, 51 48 bytes



                Edit: -3 bytes thanks to @xnor.



                (w->[r|p<-scanl1(++)w,map(!!0)w==p,r<-p]).words


                Finds acronym.



                Try it online!



                w-> .words -- let 'w' be the input list split into words
                p<-scanl1(++)w -- loop 'p' through the list starting with the first word
                -- and appending the next words one by one, e.g.
                -- "Fish","is","shiny","hero" -> "Fish","Fishis","Fishisshiny","Fishisshinyhero"
                ,map(!!0)w==p -- if the word made out of the first characters of the
                -- words of 'w' equal 'p'
                [r| r<-p] -- return the letters of 'p' - if the check before
                -- never evaluates to True then no letters, i.e. the
                -- the empty string is returned





                share|improve this answer














                Haskell, 51 48 bytes



                Edit: -3 bytes thanks to @xnor.



                (w->[r|p<-scanl1(++)w,map(!!0)w==p,r<-p]).words


                Finds acronym.



                Try it online!



                w-> .words -- let 'w' be the input list split into words
                p<-scanl1(++)w -- loop 'p' through the list starting with the first word
                -- and appending the next words one by one, e.g.
                -- "Fish","is","shiny","hero" -> "Fish","Fishis","Fishisshiny","Fishisshinyhero"
                ,map(!!0)w==p -- if the word made out of the first characters of the
                -- words of 'w' equal 'p'
                [r| r<-p] -- return the letters of 'p' - if the check before
                -- never evaluates to True then no letters, i.e. the
                -- the empty string is returned






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 2 hours ago

























                answered 20 hours ago









                nimi

                30.4k31884




                30.4k31884











                • Since you're not using x, composing (w-> ...).words would be shorter.
                  – xnor
                  10 hours ago

















                • Since you're not using x, composing (w-> ...).words would be shorter.
                  – xnor
                  10 hours ago
















                Since you're not using x, composing (w-> ...).words would be shorter.
                – xnor
                10 hours ago





                Since you're not using x, composing (w-> ...).words would be shorter.
                – xnor
                10 hours ago











                up vote
                0
                down vote














                Python 2, 106 bytes



                First option - finding recursive acronym.

                Returns result in list.





                I=input().split()
                print[' '.join(I[:i])for i in range(1,-~len(I))if[j[0]for j in I]==list(''.join(I[:i]))]


                Try it online!




                Python 2, 120 bytes



                First option - finding recursive acronym.





                def F(I,a=,r=''):
                for j in I.split():
                a+=j,
                if list(''.join(a))==[i[0]for i in I.split()]:r=' '.join(a)
                return r


                Try it online!






                share|improve this answer






















                • You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
                  – FireCubez
                  21 hours ago










                • Single letters like 'I' don't work, it should output that single letter
                  – FireCubez
                  21 hours ago










                • @FireCubez fixed
                  – Dead Possum
                  20 hours ago














                up vote
                0
                down vote














                Python 2, 106 bytes



                First option - finding recursive acronym.

                Returns result in list.





                I=input().split()
                print[' '.join(I[:i])for i in range(1,-~len(I))if[j[0]for j in I]==list(''.join(I[:i]))]


                Try it online!




                Python 2, 120 bytes



                First option - finding recursive acronym.





                def F(I,a=,r=''):
                for j in I.split():
                a+=j,
                if list(''.join(a))==[i[0]for i in I.split()]:r=' '.join(a)
                return r


                Try it online!






                share|improve this answer






















                • You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
                  – FireCubez
                  21 hours ago










                • Single letters like 'I' don't work, it should output that single letter
                  – FireCubez
                  21 hours ago










                • @FireCubez fixed
                  – Dead Possum
                  20 hours ago












                up vote
                0
                down vote










                up vote
                0
                down vote










                Python 2, 106 bytes



                First option - finding recursive acronym.

                Returns result in list.





                I=input().split()
                print[' '.join(I[:i])for i in range(1,-~len(I))if[j[0]for j in I]==list(''.join(I[:i]))]


                Try it online!




                Python 2, 120 bytes



                First option - finding recursive acronym.





                def F(I,a=,r=''):
                for j in I.split():
                a+=j,
                if list(''.join(a))==[i[0]for i in I.split()]:r=' '.join(a)
                return r


                Try it online!






                share|improve this answer















                Python 2, 106 bytes



                First option - finding recursive acronym.

                Returns result in list.





                I=input().split()
                print[' '.join(I[:i])for i in range(1,-~len(I))if[j[0]for j in I]==list(''.join(I[:i]))]


                Try it online!




                Python 2, 120 bytes



                First option - finding recursive acronym.





                def F(I,a=,r=''):
                for j in I.split():
                a+=j,
                if list(''.join(a))==[i[0]for i in I.split()]:r=' '.join(a)
                return r


                Try it online!







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 20 hours ago

























                answered 21 hours ago









                Dead Possum

                2,805623




                2,805623











                • You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
                  – FireCubez
                  21 hours ago










                • Single letters like 'I' don't work, it should output that single letter
                  – FireCubez
                  21 hours ago










                • @FireCubez fixed
                  – Dead Possum
                  20 hours ago
















                • You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
                  – FireCubez
                  21 hours ago










                • Single letters like 'I' don't work, it should output that single letter
                  – FireCubez
                  21 hours ago










                • @FireCubez fixed
                  – Dead Possum
                  20 hours ago















                You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
                – FireCubez
                21 hours ago




                You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
                – FireCubez
                21 hours ago












                Single letters like 'I' don't work, it should output that single letter
                – FireCubez
                21 hours ago




                Single letters like 'I' don't work, it should output that single letter
                – FireCubez
                21 hours ago












                @FireCubez fixed
                – Dead Possum
                20 hours ago




                @FireCubez fixed
                – Dead Possum
                20 hours ago










                up vote
                0
                down vote













                Javascript, 71 bytes



                Approach 1



                l=s=>p=s.split(' ');k=p.reduce((r,x)=>r+x[0],'');return k==p[0]?k:''


                Ungolfed:



                l=s=>
                p = s.split(' ');
                k = p.reduce((r,x)=>r+x[0],'');
                return k==p[0] ? k : '';



                • Split the string by space.

                • Create new string by taking first character from each word.

                • Compare it with the first word.





                share|improve this answer








                New contributor




                alpheus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





















                  up vote
                  0
                  down vote













                  Javascript, 71 bytes



                  Approach 1



                  l=s=>p=s.split(' ');k=p.reduce((r,x)=>r+x[0],'');return k==p[0]?k:''


                  Ungolfed:



                  l=s=>
                  p = s.split(' ');
                  k = p.reduce((r,x)=>r+x[0],'');
                  return k==p[0] ? k : '';



                  • Split the string by space.

                  • Create new string by taking first character from each word.

                  • Compare it with the first word.





                  share|improve this answer








                  New contributor




                  alpheus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Javascript, 71 bytes



                    Approach 1



                    l=s=>p=s.split(' ');k=p.reduce((r,x)=>r+x[0],'');return k==p[0]?k:''


                    Ungolfed:



                    l=s=>
                    p = s.split(' ');
                    k = p.reduce((r,x)=>r+x[0],'');
                    return k==p[0] ? k : '';



                    • Split the string by space.

                    • Create new string by taking first character from each word.

                    • Compare it with the first word.





                    share|improve this answer








                    New contributor




                    alpheus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    Javascript, 71 bytes



                    Approach 1



                    l=s=>p=s.split(' ');k=p.reduce((r,x)=>r+x[0],'');return k==p[0]?k:''


                    Ungolfed:



                    l=s=>
                    p = s.split(' ');
                    k = p.reduce((r,x)=>r+x[0],'');
                    return k==p[0] ? k : '';



                    • Split the string by space.

                    • Create new string by taking first character from each word.

                    • Compare it with the first word.






                    share|improve this answer








                    New contributor




                    alpheus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    share|improve this answer



                    share|improve this answer






                    New contributor




                    alpheus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    answered 19 hours ago









                    alpheus

                    214




                    214




                    New contributor




                    alpheus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





                    New contributor





                    alpheus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    alpheus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.




















                        up vote
                        0
                        down vote














                        K (ngn/k), 40 bytes



                        First option:



                        $[1=#:x;x;$[(*:t)~,/*:'t:" "x;*:t;`]]


                        Try it online!






                        share|improve this answer






















                        • Which of the 2 options does this work on?
                          – FireCubez
                          18 hours ago










                        • The first, outputs acronym from string input. I'll edit my post to clarify
                          – Thaufeki
                          18 hours ago















                        up vote
                        0
                        down vote














                        K (ngn/k), 40 bytes



                        First option:



                        $[1=#:x;x;$[(*:t)~,/*:'t:" "x;*:t;`]]


                        Try it online!






                        share|improve this answer






















                        • Which of the 2 options does this work on?
                          – FireCubez
                          18 hours ago










                        • The first, outputs acronym from string input. I'll edit my post to clarify
                          – Thaufeki
                          18 hours ago













                        up vote
                        0
                        down vote










                        up vote
                        0
                        down vote










                        K (ngn/k), 40 bytes



                        First option:



                        $[1=#:x;x;$[(*:t)~,/*:'t:" "x;*:t;`]]


                        Try it online!






                        share|improve this answer















                        K (ngn/k), 40 bytes



                        First option:



                        $[1=#:x;x;$[(*:t)~,/*:'t:" "x;*:t;`]]


                        Try it online!







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited 18 hours ago

























                        answered 18 hours ago









                        Thaufeki

                        15117




                        15117











                        • Which of the 2 options does this work on?
                          – FireCubez
                          18 hours ago










                        • The first, outputs acronym from string input. I'll edit my post to clarify
                          – Thaufeki
                          18 hours ago

















                        • Which of the 2 options does this work on?
                          – FireCubez
                          18 hours ago










                        • The first, outputs acronym from string input. I'll edit my post to clarify
                          – Thaufeki
                          18 hours ago
















                        Which of the 2 options does this work on?
                        – FireCubez
                        18 hours ago




                        Which of the 2 options does this work on?
                        – FireCubez
                        18 hours ago












                        The first, outputs acronym from string input. I'll edit my post to clarify
                        – Thaufeki
                        18 hours ago





                        The first, outputs acronym from string input. I'll edit my post to clarify
                        – Thaufeki
                        18 hours ago











                        up vote
                        0
                        down vote














                        JavaScript (Node.js), 70 bytes





                        s=>(s.replace(/w+/g,x=>w+=x[0]+' ?',w='^'),s.match(w+'\b')||[''])[0]


                        Try it online!






                        share|improve this answer


























                          up vote
                          0
                          down vote














                          JavaScript (Node.js), 70 bytes





                          s=>(s.replace(/w+/g,x=>w+=x[0]+' ?',w='^'),s.match(w+'\b')||[''])[0]


                          Try it online!






                          share|improve this answer
























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote










                            JavaScript (Node.js), 70 bytes





                            s=>(s.replace(/w+/g,x=>w+=x[0]+' ?',w='^'),s.match(w+'\b')||[''])[0]


                            Try it online!






                            share|improve this answer















                            JavaScript (Node.js), 70 bytes





                            s=>(s.replace(/w+/g,x=>w+=x[0]+' ?',w='^'),s.match(w+'\b')||[''])[0]


                            Try it online!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 17 hours ago

























                            answered 19 hours ago









                            l4m2

                            3,8981431




                            3,8981431



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174766%2ffind-a-recursive-acronym%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Comments

                                Popular posts from this blog

                                What does second last employer means? [closed]

                                Installing NextGIS Connect into QGIS 3?

                                One-line joke