Find a recursive acronym
Clash 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
code-golf string
 |Â
show 13 more comments
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
code-golf string
Partially related.
â AdmBorkBork
21 hours ago
What's valid English? Isgat
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
 |Â
show 13 more comments
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
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
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
code-golf string
edited 11 mins ago
asked 22 hours ago
FireCubez
1649
1649
Partially related.
â AdmBorkBork
21 hours ago
What's valid English? Isgat
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
 |Â
show 13 more comments
Partially related.
â AdmBorkBork
21 hours ago
What's valid English? Isgat
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
 |Â
show 13 more comments
13 Answers
13
active
oldest
votes
up vote
3
down vote
Japt, 13 bytes
ø
mÃÂì
VøUàéV
Try it online!
11 bytes
â Shaggy
20 hours ago
1
This fails on theppcg 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
 |Â
show 1 more comment
up vote
3
down vote
05AB1E, 16 bytes
ðáé÷ÃÂJîâ¬ýJ÷sÃÂ¥}øJ
Try it online!
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 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
21 hours ago
1
@KamilDrakari: Works now though.
â Emigna
11 hours ago
 |Â
show 6 more comments
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 Or the regex from moonheart's answer is shorter ord
only returns the ordinal value of first letter of a string, while chrs
takes a list of ords and returns a string.:(
. 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
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
add a comment |Â
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.
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
21 hours ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
21 hours ago
add a comment |Â
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.
Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails theppcgpaints
test, otherwise I would have suggested something like$!âÂÂ.words
for the if condition
â Jo King
16 hours ago
add a comment |Â
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()
Which of the 2 choices does this program do?
â FireCubez
18 hours ago
@FireCubez Updated.
â Hannes Karppila
14 hours ago
add a comment |Â
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
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
add a comment |Â
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
add a comment |Â
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
Since you're not usingx
, composing(w-> ...).words
would be shorter.
â xnor
10 hours 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
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
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
K (ngn/k), 40 bytes
First option:
$[1=#:x;x;$[(*:t)~,/*:'t:" "x;*:t;`]]
Try it online!
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
add a comment |Â
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!
add a comment |Â
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 theppcg 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
 Ã¸J
Try it online!
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 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
21 hours ago
1
@KamilDrakari: Works now though.
â Emigna
11 hours ago
 |Â
show 6 more comments
up vote
3
down vote
05AB1E, 16 bytes
ðáé÷ÃÂJîâ¬ýJ÷sÃÂ¥}øJ
Try it online!
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 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
21 hours ago
1
@KamilDrakari: Works now though.
â Emigna
11 hours ago
 |Â
show 6 more comments
up vote
3
down vote
up vote
3
down vote
05AB1E, 16 bytes
ðáé÷ÃÂJîâ¬ýJ÷sÃÂ¥}øJ
Try it online!
05AB1E, 16 bytes
ðáé÷ÃÂJîâ¬ýJ÷sÃÂ¥}øJ
Try it online!
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 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
21 hours ago
1
@KamilDrakari: Works now though.
â Emigna
11 hours ago
 |Â
show 6 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
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 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
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
 |Â
show 6 more comments
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 Or the regex from moonheart's answer is shorter ord
only returns the ordinal value of first letter of a string, while chrs
takes a list of ords and returns a string.:(
. 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
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
add a comment |Â
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 Or the regex from moonheart's answer is shorter ord
only returns the ordinal value of first letter of a string, while chrs
takes a list of ords and returns a string.:(
. 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
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
add a comment |Â
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 Or the regex from moonheart's answer is shorter ord
only returns the ordinal value of first letter of a string, while chrs
takes a list of ords and returns a string.:(
. 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
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 Or the regex from moonheart's answer is shorter ord
only returns the ordinal value of first letter of a string, while chrs
takes a list of ords and returns a string.:(
. 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
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
add a comment |Â
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
add a comment |Â
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.
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
21 hours ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
21 hours ago
add a comment |Â
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.
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
21 hours ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
21 hours ago
add a comment |Â
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.
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 21 hours ago
answered 21 hours ago
Neil
77k744173
77k744173
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
21 hours ago
@FireCubez Sorry, I was working off an older version of the question.
â Neil
21 hours 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
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
add a comment |Â
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.
Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails theppcgpaints
test, otherwise I would have suggested something like$!âÂÂ.words
for the if condition
â Jo King
16 hours ago
add a comment |Â
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.
Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails theppcgpaints
test, otherwise I would have suggested something like$!âÂÂ.words
for the if condition
â Jo King
16 hours ago
add a comment |Â
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.
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.
answered 18 hours ago
moonheart08
59210
59210
Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails theppcgpaints
test, otherwise I would have suggested something like$!âÂÂ.words
for the if condition
â Jo King
16 hours ago
add a comment |Â
Sadly, I'm still at the stage where regexes are simply madness. Unfortunately, this fails theppcgpaints
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
add a comment |Â
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()
Which of the 2 choices does this program do?
â FireCubez
18 hours ago
@FireCubez Updated.
â Hannes Karppila
14 hours ago
add a comment |Â
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()
Which of the 2 choices does this program do?
â FireCubez
18 hours ago
@FireCubez Updated.
â Hannes Karppila
14 hours ago
add a comment |Â
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()
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()
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
add a comment |Â
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
edited 10 hours ago
answered 10 hours ago
Rick Hitchcock
2,421515
2,421515
add a comment |Â
add a comment |Â
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
Since you're not usingx
, composing(w-> ...).words
would be shorter.
â xnor
10 hours ago
add a comment |Â
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
Since you're not usingx
, composing(w-> ...).words
would be shorter.
â xnor
10 hours ago
add a comment |Â
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
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
edited 2 hours ago
answered 20 hours ago
nimi
30.4k31884
30.4k31884
Since you're not usingx
, composing(w-> ...).words
would be shorter.
â xnor
10 hours ago
add a comment |Â
Since you're not usingx
, 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
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
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
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
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
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 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
add a comment |Â
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
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 19 hours ago
alpheus
214
214
New contributor
New contributor
add a comment |Â
add a comment |Â
up vote
0
down vote
K (ngn/k), 40 bytes
First option:
$[1=#:x;x;$[(*:t)~,/*:'t:" "x;*:t;`]]
Try it online!
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
add a comment |Â
up vote
0
down vote
K (ngn/k), 40 bytes
First option:
$[1=#:x;x;$[(*:t)~,/*:'t:" "x;*:t;`]]
Try it online!
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
add a comment |Â
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!
K (ngn/k), 40 bytes
First option:
$[1=#:x;x;$[(*:t)~,/*:'t:" "x;*:t;`]]
Try it online!
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
add a comment |Â
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
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
JavaScript (Node.js), 70 bytes
s=>(s.replace(/w+/g,x=>w+=x[0]+' ?',w='^'),s.match(w+'\b')||[''])[0]
Try it online!
edited 17 hours ago
answered 19 hours ago
l4m2
3,8981431
3,8981431
add a comment |Â
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%2ffind-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
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