Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
5 added 11 characters in body
source | link

Haskell, 140140 132 bytes

Thanks @nimi for saving a few bytes!

import Data.List
h s|m<-length s=nub[k|l<-head s!!0,k<-("'("++l++"':l++")"):[u++v|n<-[0..m-2],u<-s!!n,v<-s!!(m-2-n)]]:s
f n=head.(n=iterate h[[""]]!!n)$iterate h[[""]]!!0

First of all: iterate does create a recursion sequecnce of h, but this is a builtin, and by the rules we may use builtins that use recursion.

This is just a very simple recursive approach, we can generate the n-Dyck-words by putting (n-1)-Dyck-words between paranthesis, or by concatenating from shorter Dyck words. This approach however does generate duplicates, that is why we filter for unique elements using nub.

As Haskell is a functional language, it is almost impossible to do this without recursion. There is an even more direct approach, but that one is banned under the current rules.

Haskell, 140 bytes

import Data.List
h s|m<-length s=nub[k|l<-head s,k<-("("++l++")"):[u++v|n<-[0..m-2],u<-s!!n,v<-s!!(m-2-n)]]:s
f n=head.(!!n)$iterate h[[""]]

First of all: iterate does create a recursion sequecnce of h, but this is a builtin, and by the rules we may use builtins that use recursion.

This is just a very simple recursive approach, we can generate the n-Dyck-words by putting (n-1)-Dyck-words between paranthesis, or by concatenating from shorter Dyck words. This approach however does generate duplicates, that is why we filter for unique elements using nub.

As Haskell is a functional language, it is almost impossible to do this without recursion. There is an even more direct approach, but that one is banned under the current rules.

Haskell, 140 132 bytes

Thanks @nimi for saving a few bytes!

import Data.List
h s|m<-length s=nub[k|l<-s!!0,k<-('(':l++")"):[u++v|n<-[0..m-2],u<-s!!n,v<-s!!(m-2-n)]]:s
f n=iterate h[[""]]!!n!!0

First of all: iterate does create a recursion sequecnce of h, but this is a builtin, and by the rules we may use builtins that use recursion.

This is just a very simple recursive approach, we can generate the n-Dyck-words by putting (n-1)-Dyck-words between paranthesis, or by concatenating from shorter Dyck words. This approach however does generate duplicates, that is why we filter for unique elements using nub.

As Haskell is a functional language, it is almost impossible to do this without recursion. There is an even more direct approach, but that one is banned under the current rules.

    Post Undeleted by flawr
4 added 52 characters in body
source | link

Haskell, 84140 bytes

import Data.List
h s=[k|l<s|m<-length s=nub[k|l<-head s,k<-nub["()"++l,"("++l++")"):[u++v|n<-[0..m-2],l++"u<-s!!n,v<-s!!(m-2-n)"]]]]:s
f n=head.(!!n)$iterate h[""]h[[""]]

First of all: iterate does create a recursion sequecnce of h, but this is a builtin, and by the rules we may use builtins that use recursion.

This is just a very simple recursive approach, we can generate the n-Dyck-words by putting (n-1)-Dyck-words after, in between paranthesis, or before a pair of opening and closing parenthesisby concatenating from shorter Dyck words. This approach however does generate duplicates, that is why we filter for unique elements using nub. With the elimination of duplicates at each recursion step (duplicates among a list of length 3) this approach is quite efficient.

As Haskell is a functional language, it is almost impossible to do this without recursion. There is an even more direct approach, but that one is banned under the current rules.

Haskell, 84 bytes

import Data.List
h s=[k|l<-s,k<-nub["()"++l,"("++l++")",l++"()"]]
(!!)$iterate h[""]

First of all: iterate does create a recursion sequecnce of h, but this is a builtin, and by the rules we may use builtins that use recursion.

This is just a very simple recursive approach, we can generate the n-Dyck-words by putting (n-1)-Dyck-words after, in between or before a pair of opening and closing parenthesis. This approach however does generate duplicates, that is why we filter for unique elements using nub. With the elimination of duplicates at each recursion step (duplicates among a list of length 3) this approach is quite efficient.

As Haskell is a functional language, it is almost impossible to do this without recursion. There is an even more direct approach, but that one is banned under the current rules.

Haskell, 140 bytes

import Data.List
h s|m<-length s=nub[k|l<-head s,k<-("("++l++")"):[u++v|n<-[0..m-2],u<-s!!n,v<-s!!(m-2-n)]]:s
f n=head.(!!n)$iterate h[[""]]

First of all: iterate does create a recursion sequecnce of h, but this is a builtin, and by the rules we may use builtins that use recursion.

This is just a very simple recursive approach, we can generate the n-Dyck-words by putting (n-1)-Dyck-words between paranthesis, or by concatenating from shorter Dyck words. This approach however does generate duplicates, that is why we filter for unique elements using nub.

As Haskell is a functional language, it is almost impossible to do this without recursion. There is an even more direct approach, but that one is banned under the current rules.

    Post Deleted by flawr
3 added 156 characters in body
source | link

Haskell, 84 bytes

import Data.List
h s=[k|l<-s,k<-nub["()"++l,"("++l++")",l++"()"]]
(!!)$iterate h[""]

First of all: iterate does create a recursion sequecnce of h, but this is a builtin, and by the rules we may use builtins that use recursion.

This is just a very simple recursive approach, we can generate the n-Dyck-words by putting (n-1)-Dyck-words after, in between or before a pair of opening and closing parenthesis. This approach however does generate duplicates, that is why we filter for unique elements using nub. With the elimination of duplicates at each recursion step (duplicates among a list of length 3) this approach is quite efficient.

As Haskell is a functional language, it is almost impossible to do this without recursion. There is an even more direct approach, but that one is banned under the current rules.

Haskell, 84 bytes

import Data.List
h s=[k|l<-s,k<-nub["()"++l,"("++l++")",l++"()"]]
(!!)$iterate h[""]

First of all: iterate does create a recursion sequecnce of h, but this is a builtin, and by the rules we may use builtins that use recursion.

This is just a very simple recursive approach, we can generate the n-Dyck-words by putting (n-1)-Dyck-words after, in between or before a pair of opening and closing parenthesis. This approach however does generate duplicates, that is why we filter for unique elements using nub. With the elimination of duplicates at each recursion step (duplicates among a list of length 3) this approach is quite efficient.

Haskell, 84 bytes

import Data.List
h s=[k|l<-s,k<-nub["()"++l,"("++l++")",l++"()"]]
(!!)$iterate h[""]

First of all: iterate does create a recursion sequecnce of h, but this is a builtin, and by the rules we may use builtins that use recursion.

This is just a very simple recursive approach, we can generate the n-Dyck-words by putting (n-1)-Dyck-words after, in between or before a pair of opening and closing parenthesis. This approach however does generate duplicates, that is why we filter for unique elements using nub. With the elimination of duplicates at each recursion step (duplicates among a list of length 3) this approach is quite efficient.

As Haskell is a functional language, it is almost impossible to do this without recursion. There is an even more direct approach, but that one is banned under the current rules.

    Post Undeleted by flawr
2 added 156 characters in body
source | link
    Post Deleted by flawr
1
source | link