Skip to main content
4 of 14
added 16 characters in body
J.Doe
  • 2.6k
  • 11
  • 15

R, 132 bytes

This recursive approach is probably not the shortest way to do it, but it was fun to code up.

-1 thanks @Giuseppe

f=function(n,b=c("(",")"),x=b){if(!n)return(Reduce(paste0,x));sort(unique(unlist(lapply(seq(x),function(i)f(n-1,,append(x,b,i))))))}

Try it online!

J.Doe
  • 2.6k
  • 11
  • 15