Make a recursive acronym
Clash Royale CLAN TAG#URR8PPP
up vote
2
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
You have 2 choices:
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 thep
fromppcg
then adding that to the acronym, then taking thee
fromelephant
. 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 theh
fromhi
, but the sentence is now over and there are no more letters to spell outhi
and we are just left withh
which doesn't matchhi
. (The string needs an amount of words more than or equal to the amount of letters in the acronym)Make a program that takes a string of 1 or more words separated by space characters, and output a sentence that makes the input an acronym for that sentence, or output an empty string if it is impossible. It is never impossible to make a sentence if the input is 1 word long, but if we have 2 words, we get a similar problem to the one above. For example,
programming puzzles
, you would have to obviously haveprogramming puzzles
at the beginning of your outputted sentence, but if we try to convert it back to an acronym, we see that taking thep
fromprogramming
is fine, but then thep
frompuzzles
makes the acronym spell outpp..
which doesn't matchpr..
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
Guidelines
- Include which of the 2 options you chose.
- Include your byte count because this is code golf.
Test Cases
(Finding acronym) hi igloo -> hi
(Finding acronym) ppcg paints -> (impossible)
(Finding acronym) ppcg paints cool giraffes -> ppcg
(Finding acronym) I -> I
(Finding sentence) ppcg paints -> ppcg paints cool galaxies paints air in not the sea
(Finding sentence) hi -> hi invert
(Finding sentence) I -> I
Scoring
This is code-golf, so the smallest source code in bytes wins
code-golf string
 |Â
show 1 more comment
up vote
2
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
You have 2 choices:
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 thep
fromppcg
then adding that to the acronym, then taking thee
fromelephant
. 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 theh
fromhi
, but the sentence is now over and there are no more letters to spell outhi
and we are just left withh
which doesn't matchhi
. (The string needs an amount of words more than or equal to the amount of letters in the acronym)Make a program that takes a string of 1 or more words separated by space characters, and output a sentence that makes the input an acronym for that sentence, or output an empty string if it is impossible. It is never impossible to make a sentence if the input is 1 word long, but if we have 2 words, we get a similar problem to the one above. For example,
programming puzzles
, you would have to obviously haveprogramming puzzles
at the beginning of your outputted sentence, but if we try to convert it back to an acronym, we see that taking thep
fromprogramming
is fine, but then thep
frompuzzles
makes the acronym spell outpp..
which doesn't matchpr..
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
Guidelines
- Include which of the 2 options you chose.
- Include your byte count because this is code golf.
Test Cases
(Finding acronym) hi igloo -> hi
(Finding acronym) ppcg paints -> (impossible)
(Finding acronym) ppcg paints cool giraffes -> ppcg
(Finding acronym) I -> I
(Finding sentence) ppcg paints -> ppcg paints cool galaxies paints air in not the sea
(Finding sentence) hi -> hi invert
(Finding sentence) I -> I
Scoring
This is code-golf, so the smallest source code in bytes wins
code-golf string
@JoKing The challenge becomes trivial without that
â FireCubez
2 hours ago
@JoKing alright then, I can change that
â FireCubez
2 hours ago
1
In your test cases you haveppcg paints -> pp
, but it should match thefirst word or words
. Must the acronym merely be contained in the string, or does it need to start with it, or be one of the words?
â Jo King
2 hours ago
@JoKing Oh, my mistake, it should spell out the word completely
â FireCubez
1 hour ago
Partially related.
â AdmBorkBork
1 hour ago
 |Â
show 1 more comment
up vote
2
down vote
favorite
up vote
2
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
You have 2 choices:
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 thep
fromppcg
then adding that to the acronym, then taking thee
fromelephant
. 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 theh
fromhi
, but the sentence is now over and there are no more letters to spell outhi
and we are just left withh
which doesn't matchhi
. (The string needs an amount of words more than or equal to the amount of letters in the acronym)Make a program that takes a string of 1 or more words separated by space characters, and output a sentence that makes the input an acronym for that sentence, or output an empty string if it is impossible. It is never impossible to make a sentence if the input is 1 word long, but if we have 2 words, we get a similar problem to the one above. For example,
programming puzzles
, you would have to obviously haveprogramming puzzles
at the beginning of your outputted sentence, but if we try to convert it back to an acronym, we see that taking thep
fromprogramming
is fine, but then thep
frompuzzles
makes the acronym spell outpp..
which doesn't matchpr..
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
Guidelines
- Include which of the 2 options you chose.
- Include your byte count because this is code golf.
Test Cases
(Finding acronym) hi igloo -> hi
(Finding acronym) ppcg paints -> (impossible)
(Finding acronym) ppcg paints cool giraffes -> ppcg
(Finding acronym) I -> I
(Finding sentence) ppcg paints -> ppcg paints cool galaxies paints air in not the sea
(Finding sentence) hi -> hi invert
(Finding sentence) I -> I
Scoring
This is code-golf, so the smallest source code in bytes wins
code-golf string
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
You have 2 choices:
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 thep
fromppcg
then adding that to the acronym, then taking thee
fromelephant
. 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 theh
fromhi
, but the sentence is now over and there are no more letters to spell outhi
and we are just left withh
which doesn't matchhi
. (The string needs an amount of words more than or equal to the amount of letters in the acronym)Make a program that takes a string of 1 or more words separated by space characters, and output a sentence that makes the input an acronym for that sentence, or output an empty string if it is impossible. It is never impossible to make a sentence if the input is 1 word long, but if we have 2 words, we get a similar problem to the one above. For example,
programming puzzles
, you would have to obviously haveprogramming puzzles
at the beginning of your outputted sentence, but if we try to convert it back to an acronym, we see that taking thep
fromprogramming
is fine, but then thep
frompuzzles
makes the acronym spell outpp..
which doesn't matchpr..
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
Guidelines
- Include which of the 2 options you chose.
- Include your byte count because this is code golf.
Test Cases
(Finding acronym) hi igloo -> hi
(Finding acronym) ppcg paints -> (impossible)
(Finding acronym) ppcg paints cool giraffes -> ppcg
(Finding acronym) I -> I
(Finding sentence) ppcg paints -> ppcg paints cool galaxies paints air in not the sea
(Finding sentence) hi -> hi invert
(Finding sentence) I -> I
Scoring
This is code-golf, so the smallest source code in bytes wins
code-golf string
code-golf string
edited 1 hour ago
asked 2 hours ago
FireCubez
1398
1398
@JoKing The challenge becomes trivial without that
â FireCubez
2 hours ago
@JoKing alright then, I can change that
â FireCubez
2 hours ago
1
In your test cases you haveppcg paints -> pp
, but it should match thefirst word or words
. Must the acronym merely be contained in the string, or does it need to start with it, or be one of the words?
â Jo King
2 hours ago
@JoKing Oh, my mistake, it should spell out the word completely
â FireCubez
1 hour ago
Partially related.
â AdmBorkBork
1 hour ago
 |Â
show 1 more comment
@JoKing The challenge becomes trivial without that
â FireCubez
2 hours ago
@JoKing alright then, I can change that
â FireCubez
2 hours ago
1
In your test cases you haveppcg paints -> pp
, but it should match thefirst word or words
. Must the acronym merely be contained in the string, or does it need to start with it, or be one of the words?
â Jo King
2 hours ago
@JoKing Oh, my mistake, it should spell out the word completely
â FireCubez
1 hour ago
Partially related.
â AdmBorkBork
1 hour ago
@JoKing The challenge becomes trivial without that
â FireCubez
2 hours ago
@JoKing The challenge becomes trivial without that
â FireCubez
2 hours ago
@JoKing alright then, I can change that
â FireCubez
2 hours ago
@JoKing alright then, I can change that
â FireCubez
2 hours ago
1
1
In your test cases you have
ppcg paints -> pp
, but it should match the first word or words
. Must the acronym merely be contained in the string, or does it need to start with it, or be one of the words?â Jo King
2 hours ago
In your test cases you have
ppcg paints -> pp
, but it should match the first word or words
. Must the acronym merely be contained in the string, or does it need to start with it, or be one of the words?â Jo King
2 hours ago
@JoKing Oh, my mistake, it should spell out the word completely
â FireCubez
1 hour ago
@JoKing Oh, my mistake, it should spell out the word completely
â FireCubez
1 hour ago
Partially related.
â AdmBorkBork
1 hour ago
Partially related.
â AdmBorkBork
1 hour ago
 |Â
show 1 more comment
9 Answers
9
active
oldest
votes
up vote
1
down vote
05AB1E, 13 bytes
Finds acronym
ðáé÷ÃÂJîâ¬ýJQ}û
Try it online!
Explanation
ðá # split input on spaces
é # store result in register
ֈ} # filter the prefixes of the result
# keep only those that
J # when joined to one string
Q # are equal to
îâ¬ý # the first letter of each word in the input
J # joined to one string
û # join on spaces and newlines
1
Why did it change toð¡
instead of#
in your last edit? Some special test cases I'm not taking into account?
â Kevin Cruijssen
1 hour ago
@KevinCruijssen: Because#
would fail for single word input outputting the input instead of an empty string.
â Emigna
1 hour 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
1 hour ago
@KevinCruijssen: I think it's mainly due to#
also being used asquit 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
1 hour ago
Hmm, you could be right it's related. I always sawstop loop if true
andsplit on space
as two different functions, both using#
. So the compiler encountering a#
would do a check: Is an infinite loop running? Yes -> stop it; No -> Split the top of the stack on spaces. If it's implemented like this pseudo-code, it would be strange if#
asstop loop if true
would be wrapped in a list, since it would never go into the else-clause in the compiler. But perhaps the pseudo-code isn't so easy to implement in Elixir as I think, in which case you're perhaps right it's related.
â Kevin Cruijssen
1 hour ago
 |Â
show 4 more comments
up vote
1
down vote
Japt, 13 11 bytes
-2 bytes from @Shaggy
Finds acronym
ø
mÃÂì
ÃÂöVéV
Try it online!
11 bytes
â Shaggy
28 mins ago
add a comment |Â
up vote
0
down vote
Perl 6, 37 bytes
~.words>>.ord.chrs.grep(*âÂÂ.words)
Try it online!
First option.
You aren't required to output "IMPOSSIBLE" now
â FireCubez
2 hours ago
add a comment |Â
up vote
0
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.
For ppcg paints, output is invalid, it should output nothing sincepp
only spells a portion of the first word, instead of all of it
â FireCubez
1 hour ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
1 hour ago
add a comment |Â
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!
You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
â FireCubez
2 hours ago
Single letters like 'I' don't work, it should output that single letter
â FireCubez
1 hour ago
@FireCubez fixed
â Dead Possum
54 mins ago
add a comment |Â
up vote
0
down vote
Haskell, 40 bytes
f x|w<-words x=[0|map(!!0)w==w!!0]>>w!!0
Finds acronym.
Try it online!
w<-words x -- let w be the input string split into words
map(!!0)w==w!!0 -- check if the first character of each word are
-- equal to the first word
[0| <Test> ] >> <Out> -- return <Out> (here the first word) if <Test> is True
-- else an empty string [1]
[1] taken from Tips for golfing in Haskell
add a comment |Â
up vote
0
down vote
Ruby -apl
, 28 bytes
$_=$F.map(&:chr).join[$F[0]]
Try it online!
Option 1 - finds the acronym if it exists.
add a comment |Â
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.
New contributor
add a comment |Â
up vote
0
down vote
JavaScript, 49 bytes
s=>(a=s.split` `).map(x=>x[0]).join``==a[0]&&a[0]
Try it online
Fail onppcg paints cool giraffes pa ac ik ne td sr
â l4m2
8 mins ago
@lm42,ppcgpaints != ppcg
.
â Shaggy
3 mins ago
add a comment |Â
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
05AB1E, 13 bytes
Finds acronym
ðáé÷ÃÂJîâ¬ýJQ}û
Try it online!
Explanation
ðá # split input on spaces
é # store result in register
ֈ} # filter the prefixes of the result
# keep only those that
J # when joined to one string
Q # are equal to
îâ¬ý # the first letter of each word in the input
J # joined to one string
û # join on spaces and newlines
1
Why did it change toð¡
instead of#
in your last edit? Some special test cases I'm not taking into account?
â Kevin Cruijssen
1 hour ago
@KevinCruijssen: Because#
would fail for single word input outputting the input instead of an empty string.
â Emigna
1 hour 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
1 hour ago
@KevinCruijssen: I think it's mainly due to#
also being used asquit 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
1 hour ago
Hmm, you could be right it's related. I always sawstop loop if true
andsplit on space
as two different functions, both using#
. So the compiler encountering a#
would do a check: Is an infinite loop running? Yes -> stop it; No -> Split the top of the stack on spaces. If it's implemented like this pseudo-code, it would be strange if#
asstop loop if true
would be wrapped in a list, since it would never go into the else-clause in the compiler. But perhaps the pseudo-code isn't so easy to implement in Elixir as I think, in which case you're perhaps right it's related.
â Kevin Cruijssen
1 hour ago
 |Â
show 4 more comments
up vote
1
down vote
05AB1E, 13 bytes
Finds acronym
ðáé÷ÃÂJîâ¬ýJQ}û
Try it online!
Explanation
ðá # split input on spaces
é # store result in register
ֈ} # filter the prefixes of the result
# keep only those that
J # when joined to one string
Q # are equal to
îâ¬ý # the first letter of each word in the input
J # joined to one string
û # join on spaces and newlines
1
Why did it change toð¡
instead of#
in your last edit? Some special test cases I'm not taking into account?
â Kevin Cruijssen
1 hour ago
@KevinCruijssen: Because#
would fail for single word input outputting the input instead of an empty string.
â Emigna
1 hour 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
1 hour ago
@KevinCruijssen: I think it's mainly due to#
also being used asquit 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
1 hour ago
Hmm, you could be right it's related. I always sawstop loop if true
andsplit on space
as two different functions, both using#
. So the compiler encountering a#
would do a check: Is an infinite loop running? Yes -> stop it; No -> Split the top of the stack on spaces. If it's implemented like this pseudo-code, it would be strange if#
asstop loop if true
would be wrapped in a list, since it would never go into the else-clause in the compiler. But perhaps the pseudo-code isn't so easy to implement in Elixir as I think, in which case you're perhaps right it's related.
â Kevin Cruijssen
1 hour ago
 |Â
show 4 more comments
up vote
1
down vote
up vote
1
down vote
05AB1E, 13 bytes
Finds acronym
ðáé÷ÃÂJîâ¬ýJQ}û
Try it online!
Explanation
ðá # split input on spaces
é # store result in register
ֈ} # filter the prefixes of the result
# keep only those that
J # when joined to one string
Q # are equal to
îâ¬ý # the first letter of each word in the input
J # joined to one string
û # join on spaces and newlines
05AB1E, 13 bytes
Finds acronym
ðáé÷ÃÂJîâ¬ýJQ}û
Try it online!
Explanation
ðá # split input on spaces
é # store result in register
ֈ} # filter the prefixes of the result
# keep only those that
J # when joined to one string
Q # are equal to
îâ¬ý # the first letter of each word in the input
J # joined to one string
û # join on spaces and newlines
edited 1 hour ago
answered 1 hour 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
1 hour ago
@KevinCruijssen: Because#
would fail for single word input outputting the input instead of an empty string.
â Emigna
1 hour 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
1 hour ago
@KevinCruijssen: I think it's mainly due to#
also being used asquit 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
1 hour ago
Hmm, you could be right it's related. I always sawstop loop if true
andsplit on space
as two different functions, both using#
. So the compiler encountering a#
would do a check: Is an infinite loop running? Yes -> stop it; No -> Split the top of the stack on spaces. If it's implemented like this pseudo-code, it would be strange if#
asstop loop if true
would be wrapped in a list, since it would never go into the else-clause in the compiler. But perhaps the pseudo-code isn't so easy to implement in Elixir as I think, in which case you're perhaps right it's related.
â Kevin Cruijssen
1 hour ago
 |Â
show 4 more comments
1
Why did it change toð¡
instead of#
in your last edit? Some special test cases I'm not taking into account?
â Kevin Cruijssen
1 hour ago
@KevinCruijssen: Because#
would fail for single word input outputting the input instead of an empty string.
â Emigna
1 hour 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
1 hour ago
@KevinCruijssen: I think it's mainly due to#
also being used asquit 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
1 hour ago
Hmm, you could be right it's related. I always sawstop loop if true
andsplit on space
as two different functions, both using#
. So the compiler encountering a#
would do a check: Is an infinite loop running? Yes -> stop it; No -> Split the top of the stack on spaces. If it's implemented like this pseudo-code, it would be strange if#
asstop loop if true
would be wrapped in a list, since it would never go into the else-clause in the compiler. But perhaps the pseudo-code isn't so easy to implement in Elixir as I think, in which case you're perhaps right it's related.
â Kevin Cruijssen
1 hour 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
1 hour ago
Why did it change to
ð¡
instead of #
in your last edit? Some special test cases I'm not taking into account?â Kevin Cruijssen
1 hour ago
@KevinCruijssen: Because
#
would fail for single word input outputting the input instead of an empty string.â Emigna
1 hour ago
@KevinCruijssen: Because
#
would fail for single word input outputting the input instead of an empty string.â Emigna
1 hour 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
1 hour 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
1 hour 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
1 hour 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
1 hour ago
Hmm, you could be right it's related. I always saw
stop loop if true
and split on space
as two different functions, both using #
. So the compiler encountering a #
would do a check: Is an infinite loop running? Yes -> stop it; No -> Split the top of the stack on spaces. If it's implemented like this pseudo-code, it would be strange if #
as stop loop if true
would be wrapped in a list, since it would never go into the else-clause in the compiler. But perhaps the pseudo-code isn't so easy to implement in Elixir as I think, in which case you're perhaps right it's related.â Kevin Cruijssen
1 hour ago
Hmm, you could be right it's related. I always saw
stop loop if true
and split on space
as two different functions, both using #
. So the compiler encountering a #
would do a check: Is an infinite loop running? Yes -> stop it; No -> Split the top of the stack on spaces. If it's implemented like this pseudo-code, it would be strange if #
as stop loop if true
would be wrapped in a list, since it would never go into the else-clause in the compiler. But perhaps the pseudo-code isn't so easy to implement in Elixir as I think, in which case you're perhaps right it's related.â Kevin Cruijssen
1 hour ago
 |Â
show 4 more comments
up vote
1
down vote
Japt, 13 11 bytes
-2 bytes from @Shaggy
Finds acronym
ø
mÃÂì
ÃÂöVéV
Try it online!
11 bytes
â Shaggy
28 mins ago
add a comment |Â
up vote
1
down vote
Japt, 13 11 bytes
-2 bytes from @Shaggy
Finds acronym
ø
mÃÂì
ÃÂöVéV
Try it online!
11 bytes
â Shaggy
28 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Japt, 13 11 bytes
-2 bytes from @Shaggy
Finds acronym
ø
mÃÂì
ÃÂöVéV
Try it online!
Japt, 13 11 bytes
-2 bytes from @Shaggy
Finds acronym
ø
mÃÂì
ÃÂöVéV
Try it online!
edited 4 secs ago
answered 2 hours ago
Luis felipe De jesus Munoz
3,39711049
3,39711049
11 bytes
â Shaggy
28 mins ago
add a comment |Â
11 bytes
â Shaggy
28 mins ago
11 bytes
â Shaggy
28 mins ago
11 bytes
â Shaggy
28 mins ago
add a comment |Â
up vote
0
down vote
Perl 6, 37 bytes
~.words>>.ord.chrs.grep(*âÂÂ.words)
Try it online!
First option.
You aren't required to output "IMPOSSIBLE" now
â FireCubez
2 hours ago
add a comment |Â
up vote
0
down vote
Perl 6, 37 bytes
~.words>>.ord.chrs.grep(*âÂÂ.words)
Try it online!
First option.
You aren't required to output "IMPOSSIBLE" now
â FireCubez
2 hours ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Perl 6, 37 bytes
~.words>>.ord.chrs.grep(*âÂÂ.words)
Try it online!
First option.
Perl 6, 37 bytes
~.words>>.ord.chrs.grep(*âÂÂ.words)
Try it online!
First option.
edited 2 hours ago
answered 2 hours ago
Jo King
17.9k24198
17.9k24198
You aren't required to output "IMPOSSIBLE" now
â FireCubez
2 hours ago
add a comment |Â
You aren't required to output "IMPOSSIBLE" now
â FireCubez
2 hours ago
You aren't required to output "IMPOSSIBLE" now
â FireCubez
2 hours ago
You aren't required to output "IMPOSSIBLE" now
â FireCubez
2 hours ago
add a comment |Â
up vote
0
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.
For ppcg paints, output is invalid, it should output nothing sincepp
only spells a portion of the first word, instead of all of it
â FireCubez
1 hour ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
1 hour ago
add a comment |Â
up vote
0
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.
For ppcg paints, output is invalid, it should output nothing sincepp
only spells a portion of the first word, instead of all of it
â FireCubez
1 hour ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
1 hour ago
add a comment |Â
up vote
0
down vote
up vote
0
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.
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.
edited 1 hour ago
answered 1 hour ago
Neil
76.9k744173
76.9k744173
For ppcg paints, output is invalid, it should output nothing sincepp
only spells a portion of the first word, instead of all of it
â FireCubez
1 hour ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
1 hour ago
add a comment |Â
For ppcg paints, output is invalid, it should output nothing sincepp
only spells a portion of the first word, instead of all of it
â FireCubez
1 hour ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
1 hour 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
1 hour 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
1 hour ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
1 hour ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
1 hour ago
add a comment |Â
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!
You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
â FireCubez
2 hours ago
Single letters like 'I' don't work, it should output that single letter
â FireCubez
1 hour ago
@FireCubez fixed
â Dead Possum
54 mins ago
add a comment |Â
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!
You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
â FireCubez
2 hours ago
Single letters like 'I' don't work, it should output that single letter
â FireCubez
1 hour ago
@FireCubez fixed
â Dead Possum
54 mins ago
add a comment |Â
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!
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!
edited 54 mins ago
answered 2 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
2 hours ago
Single letters like 'I' don't work, it should output that single letter
â FireCubez
1 hour ago
@FireCubez fixed
â Dead Possum
54 mins ago
add a comment |Â
You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
â FireCubez
2 hours ago
Single letters like 'I' don't work, it should output that single letter
â FireCubez
1 hour ago
@FireCubez fixed
â Dead Possum
54 mins ago
You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
â FireCubez
2 hours ago
You aren't required to output "IMPOSSIBLE" as per @JoKing 's request, that might decrease your byte count
â FireCubez
2 hours ago
Single letters like 'I' don't work, it should output that single letter
â FireCubez
1 hour ago
Single letters like 'I' don't work, it should output that single letter
â FireCubez
1 hour ago
@FireCubez fixed
â Dead Possum
54 mins ago
@FireCubez fixed
â Dead Possum
54 mins ago
add a comment |Â
up vote
0
down vote
Haskell, 40 bytes
f x|w<-words x=[0|map(!!0)w==w!!0]>>w!!0
Finds acronym.
Try it online!
w<-words x -- let w be the input string split into words
map(!!0)w==w!!0 -- check if the first character of each word are
-- equal to the first word
[0| <Test> ] >> <Out> -- return <Out> (here the first word) if <Test> is True
-- else an empty string [1]
[1] taken from Tips for golfing in Haskell
add a comment |Â
up vote
0
down vote
Haskell, 40 bytes
f x|w<-words x=[0|map(!!0)w==w!!0]>>w!!0
Finds acronym.
Try it online!
w<-words x -- let w be the input string split into words
map(!!0)w==w!!0 -- check if the first character of each word are
-- equal to the first word
[0| <Test> ] >> <Out> -- return <Out> (here the first word) if <Test> is True
-- else an empty string [1]
[1] taken from Tips for golfing in Haskell
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Haskell, 40 bytes
f x|w<-words x=[0|map(!!0)w==w!!0]>>w!!0
Finds acronym.
Try it online!
w<-words x -- let w be the input string split into words
map(!!0)w==w!!0 -- check if the first character of each word are
-- equal to the first word
[0| <Test> ] >> <Out> -- return <Out> (here the first word) if <Test> is True
-- else an empty string [1]
[1] taken from Tips for golfing in Haskell
Haskell, 40 bytes
f x|w<-words x=[0|map(!!0)w==w!!0]>>w!!0
Finds acronym.
Try it online!
w<-words x -- let w be the input string split into words
map(!!0)w==w!!0 -- check if the first character of each word are
-- equal to the first word
[0| <Test> ] >> <Out> -- return <Out> (here the first word) if <Test> is True
-- else an empty string [1]
[1] taken from Tips for golfing in Haskell
edited 23 mins ago
answered 33 mins ago
nimi
30.4k31884
30.4k31884
add a comment |Â
add a comment |Â
up vote
0
down vote
Ruby -apl
, 28 bytes
$_=$F.map(&:chr).join[$F[0]]
Try it online!
Option 1 - finds the acronym if it exists.
add a comment |Â
up vote
0
down vote
Ruby -apl
, 28 bytes
$_=$F.map(&:chr).join[$F[0]]
Try it online!
Option 1 - finds the acronym if it exists.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Ruby -apl
, 28 bytes
$_=$F.map(&:chr).join[$F[0]]
Try it online!
Option 1 - finds the acronym if it exists.
Ruby -apl
, 28 bytes
$_=$F.map(&:chr).join[$F[0]]
Try it online!
Option 1 - finds the acronym if it exists.
answered 17 mins ago
Kirill L.
2,9661117
2,9661117
add a comment |Â
add a comment |Â
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.
New contributor
add a comment |Â
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.
New contributor
add a comment |Â
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.
New contributor
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.
New contributor
New contributor
answered 9 mins ago
alpheus
214
214
New contributor
New contributor
add a comment |Â
add a comment |Â
up vote
0
down vote
JavaScript, 49 bytes
s=>(a=s.split` `).map(x=>x[0]).join``==a[0]&&a[0]
Try it online
Fail onppcg paints cool giraffes pa ac ik ne td sr
â l4m2
8 mins ago
@lm42,ppcgpaints != ppcg
.
â Shaggy
3 mins ago
add a comment |Â
up vote
0
down vote
JavaScript, 49 bytes
s=>(a=s.split` `).map(x=>x[0]).join``==a[0]&&a[0]
Try it online
Fail onppcg paints cool giraffes pa ac ik ne td sr
â l4m2
8 mins ago
@lm42,ppcgpaints != ppcg
.
â Shaggy
3 mins ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
JavaScript, 49 bytes
s=>(a=s.split` `).map(x=>x[0]).join``==a[0]&&a[0]
Try it online
JavaScript, 49 bytes
s=>(a=s.split` `).map(x=>x[0]).join``==a[0]&&a[0]
Try it online
answered 9 mins ago
Shaggy
17.4k21663
17.4k21663
Fail onppcg paints cool giraffes pa ac ik ne td sr
â l4m2
8 mins ago
@lm42,ppcgpaints != ppcg
.
â Shaggy
3 mins ago
add a comment |Â
Fail onppcg paints cool giraffes pa ac ik ne td sr
â l4m2
8 mins ago
@lm42,ppcgpaints != ppcg
.
â Shaggy
3 mins ago
Fail on
ppcg paints cool giraffes pa ac ik ne td sr
â l4m2
8 mins ago
Fail on
ppcg paints cool giraffes pa ac ik ne td sr
â l4m2
8 mins ago
@lm42,
ppcgpaints != ppcg
.â Shaggy
3 mins ago
@lm42,
ppcgpaints != ppcg
.â Shaggy
3 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174766%2fmake-a-recursive-acronym%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@JoKing The challenge becomes trivial without that
â FireCubez
2 hours ago
@JoKing alright then, I can change that
â FireCubez
2 hours ago
1
In your test cases you have
ppcg paints -> pp
, but it should match thefirst word or words
. Must the acronym merely be contained in the string, or does it need to start with it, or be one of the words?â Jo King
2 hours ago
@JoKing Oh, my mistake, it should spell out the word completely
â FireCubez
1 hour ago
Partially related.
â AdmBorkBork
1 hour ago