# Tag Info

0

Unix TMG, 51 byte p:parse(s)s:smark any(!<<>>)scopy s/d={2<(>1<)>}d:; Works by recursive descent parsing. Exploits absence of semicolons between parsing rules to make it two bytes shorter.

0

Haskell, 138 Bytes f x=let g z x=case x of{[]->z;a:b->if a==z!!0then g(tail z)b else g(case a of{'('->')';'['->']';'{'->'}';'<'->'>';_->' '}:z)b}in" "==g" "x de-golfed: f x= --define a function f let g z x=case x of{ ...

0

GolfScript, 12 bytes .'('*')'@,(* What a cute little solution! . #Duplicate entry string '('* #Join the string with left-paren ')' #Right paren string @ #Bring up our duplicate , #Count the number of characters ( #Decrease that number by 1 * #Add that many ')' to the end Try it ...

0

Burlesque, 16 bytes '([]sa2./')j.*.+ Try it online! '([] # Insert "(" between each char sa2./ # Find length/2 ')j.* # That many ")"s .+ # Concatenate

1

Python 2, 93 bytes f=lambda s,n:n and re.sub('\\b'+''.join(zip(*s.split())[0]),'('+s+')',f(s,n-1))or s import re Try it online! Similar to a few other answers. If simple substitutions were allowed, I could do... Python 2, 78 bytes f=lambda s,n:n and f(s,n-1).replace(''.join(zip(*s.split())[0]),'('+s+')')or s Try it online! Except I didn't see the ...

2

Python 3, 104 96 bytes -7 bytes thanks to @DeathIncarnate, and another -1 byte thanks to @wastl import re f=lambda s,n:n and re.sub('\\b'+''.join(c[0]for c in s.split()),f'({s})',f(s,n-1))or s Try it online! Explanation: re.sub( '\\b'+''.join(c[0]for c in s.split()), # match all acronyms that starts on a word boundary '('+s+')', ...

0

sed 4.2.2, 180 bytes h s/(.)[^ ]* */\1/g G s/$/\n/ G h N s/.*\n// tx :l s/^(.*)\n(.*)\b\1(.*)\n(.*)\n(.*)/\1\n\2\n(\5)\3\4\n\5/ tl s/\n(.*)\n(.*)\n/\n\1\2\n\n/ x tx :x s/.// x tl s/.*\n(.*)\n.*\n.*/\1/ Try it online! Well, finding one part of input in another part of input is not that simple in sed. Input is on two lines: first line is the acronym string; ... 0 Python 3, 123 106 118 bytes Rolled back to my initial post. Chas Brown kindly pointed out I was going down a rabbit hole. Added 17 bytes to fix word boundary bug. import re def f(a,n): o=a for i in[1]*n:a=re.sub(r'\b'+''.join([i[0]for i in o.split()])+r'\b',f"({o})",a) return a Try it online! 2 Perl 5 -apl, 49 43 bytes /./,$p.=$&for@F;for$a(1..<>){s/\b$p/(@F)/g} Try it online! 1 Retina, 48 bytes ~($ ¶($%) (.).*? (?=.*¶)$1 ^(.+)¶ 1A¶$1+\b Try it online! Takes the expansion count and acronym string on separate lines. Explanation: ~( After performing the script, interpret the result as a new script to be evaluated on the original input.$ ¶($%) Append a space to the string, and append a copy of the string wrapped in ()s ... 3 Perl 6, 48 bytes {($^s,{S:g/$([~]$s~~m:g/<<./)/($s)/}...*)[$^x]} Try it online! Explanation { } # Anonymous block ( , ...*) # Construct infinite sequence $^s # starting with input string. { } # ... 7 JavaScript (ES9), 88 85 82 bytes Takes input as (string)(n). s=>g=n=>n?s.replace(eval(/\\b${s.match(/(?<=^| )./g).join}/g),(\${g(n-1)})):s Try it online! Commented s => // s = string g = n => // g is a recursive function taking the counter n n ? // if n is not ...

5

05AB1E, 27 25 22 bytes ðìÐ#€нJðìs" (ÿ )"Iи.:¦ Try it online! To make sure we only match the acronym at the beginning of a word, we match an extra leading space. This results in extra spaces in the output, which is allowed. ðì # prepend a space to the input Ð # triplicate #€нJ # acronymize (...

6

APL (Dyalog Extended), 33 32 bytes -1 byte thanks to Bubbler. Anonymous infix lambda. Takes count as left argument and string as right argument. {('\b',⊃¨⍵⊆⍨≠⍵)⎕R(1⌽')(',⍵)⍣⍺⊢⍵} Try it online! {…} "dfn"; number is ⍺ and text is ⍵:  ⊢⍵ on the text:  ⍣⍺ repeat given number of times  (…)⎕R(…) PCRE Replace:   ')(',⍵ the text prefixed by ")("   1⌽ ...

0

Unix TMG, 83 bytes Another compiler-compiler solution (in addition to Yacc). p:s parse((any(!<<>>)|={<1>}));s:b s/d;d:;b:<[>x<]>|<{>x<}>|<(>x<)>|<<>x<>>;x:s|(); Unlike Yacc, it works by recursive-descent parsing. It outputs "1" on success, nothing – otherwise. Expanded: p: s parse((...

Top 50 recent answers are included