Skip to main content
edited body
Source Link
Wheat Wizard
  • 100k
  • 22
  • 282
  • 661

Haskell + hgl, 13 bytes

cP$h_<*h'>~ʃ

If you can simply submit a parser object, then that can be 10 bytes:

h_<*h'>~ʃ

Explanation

  • h_ parses at least one thing off the front of a list (think .+ in regex).
  • h' parses any amount off the front of a list (think .* in regex).
  • ʃ is a function which takes an string and produces a parser which matches exactly that string.

We combine the two with <* which runs both sequentially giving the result of the first. Then we bind this to ʃ, so that the result of h_ is passed as the input to ʃ.

In do notation this would be

do x<-h_;h';ʃ x

Described in plain English this matches any string that contains the same non-empty section at both the start and end.

Non-parser, 17 15 bytes

The parsers are obviously the way to go for this challenge, but I thought I'd give it a go without them to see how good hgl does.

lt 2<(cn**sw)sx

Explanation

  • sx gets all prefixes of a list
  • sw checks if a particular list starts with another.
  • cn counts the number of elements that satisfy a predicate.
  • (**) is an infix for liftA2.

So altogether (cn**sw)sx counts the number of suffixes of the list are also prefixes.

Now, the empty string and the input string should always pass this test. So we want to test if there is another string which also is both a prefix and a suffix. So we use lt 2 to check that's greater than 2.

Notes

Some things that could have been better for hgl in this challenge.

  • There should be a function lt2=lt 2 (and gt1, lt3 etc.). That would have saved a byte here.
  • (**) has the default precedence which although not causing any issues here, could probably be improved.
  • Variants of px and sx that give for example non-empty or strict prefixes / suffixes would probably be useful. If I had a function that specifically gave non-empty and strict suffixes then I could just do ay**sw$sxsay**sw$sxS (where sxssxS is the imagined function) for 10 bytes.

Haskell + hgl, 13 bytes

cP$h_<*h'>~ʃ

If you can simply submit a parser object, then that can be 10 bytes:

h_<*h'>~ʃ

Explanation

  • h_ parses at least one thing off the front of a list (think .+ in regex).
  • h' parses any amount off the front of a list (think .* in regex).
  • ʃ is a function which takes an string and produces a parser which matches exactly that string.

We combine the two with <* which runs both sequentially giving the result of the first. Then we bind this to ʃ, so that the result of h_ is passed as the input to ʃ.

In do notation this would be

do x<-h_;h';ʃ x

Described in plain English this matches any string that contains the same non-empty section at both the start and end.

Non-parser, 17 15 bytes

The parsers are obviously the way to go for this challenge, but I thought I'd give it a go without them to see how good hgl does.

lt 2<(cn**sw)sx

Explanation

  • sx gets all prefixes of a list
  • sw checks if a particular list starts with another.
  • cn counts the number of elements that satisfy a predicate.
  • (**) is an infix for liftA2.

So altogether (cn**sw)sx counts the number of suffixes of the list are also prefixes.

Now, the empty string and the input string should always pass this test. So we want to test if there is another string which also is both a prefix and a suffix. So we use lt 2 to check that's greater than 2.

Notes

Some things that could have been better for hgl in this challenge.

  • There should be a function lt2=lt 2 (and gt1, lt3 etc.). That would have saved a byte here.
  • (**) has the default precedence which although not causing any issues here, could probably be improved.
  • Variants of px and sx that give for example non-empty or strict prefixes / suffixes would probably be useful. If I had a function that specifically gave non-empty and strict suffixes then I could just do ay**sw$sxs (where sxs is the imagined function) for 10 bytes.

Haskell + hgl, 13 bytes

cP$h_<*h'>~ʃ

If you can simply submit a parser object, then that can be 10 bytes:

h_<*h'>~ʃ

Explanation

  • h_ parses at least one thing off the front of a list (think .+ in regex).
  • h' parses any amount off the front of a list (think .* in regex).
  • ʃ is a function which takes an string and produces a parser which matches exactly that string.

We combine the two with <* which runs both sequentially giving the result of the first. Then we bind this to ʃ, so that the result of h_ is passed as the input to ʃ.

In do notation this would be

do x<-h_;h';ʃ x

Described in plain English this matches any string that contains the same non-empty section at both the start and end.

Non-parser, 17 15 bytes

The parsers are obviously the way to go for this challenge, but I thought I'd give it a go without them to see how good hgl does.

lt 2<(cn**sw)sx

Explanation

  • sx gets all prefixes of a list
  • sw checks if a particular list starts with another.
  • cn counts the number of elements that satisfy a predicate.
  • (**) is an infix for liftA2.

So altogether (cn**sw)sx counts the number of suffixes of the list are also prefixes.

Now, the empty string and the input string should always pass this test. So we want to test if there is another string which also is both a prefix and a suffix. So we use lt 2 to check that's greater than 2.

Notes

Some things that could have been better for hgl in this challenge.

  • There should be a function lt2=lt 2 (and gt1, lt3 etc.). That would have saved a byte here.
  • (**) has the default precedence which although not causing any issues here, could probably be improved.
  • Variants of px and sx that give for example non-empty or strict prefixes / suffixes would probably be useful. If I had a function that specifically gave non-empty and strict suffixes then I could just do ay**sw$sxS (where sxS is the imagined function) for 10 bytes.
deleted 28 characters in body
Source Link
Wheat Wizard
  • 100k
  • 22
  • 282
  • 661

Haskell + hgl, 13 bytes

cP$h_<*h'>~ʃ

If you can simply submit a parser object, then that can be 10 bytes:

h_<*h'>~ʃ

Explanation

  • h_ parses at least one thing off the front of a list (think .+ in regex).
  • h' parses any amount off the front of a list (think .* in regex).
  • ʃ is a function which takes an string and produces a parser which matches exactly that string.

We combine the two with <* which runs both sequentially giving the result of the first. Then we bind this to ʃ, so that the result of h_ is passed as the input to ʃ.

In do notation this would be

do x<-h_;h';ʃ x

Described in plain English this matches any string that contains the same non-empty section at both the start and end.

Non-parser, 17 15 bytes

The parsers are obviously the way to go for this challenge, but I thought I'd give it a go without them to see how good hgl does.

lt 2<(cn**sw)sx

Explanation

  • sx gets all prefixes of a list
  • sw checks if a particular list starts with another.
  • cn counts the number of elements that satisfy a predicate.
  • (**) is an infix for liftA2.

So altogether (cn**sw)sx counts the number of suffixes of the list are also prefixes.

Now, the empty string and the input string should always pass this test. So we want to test if there is another string which also is both a prefix and a suffix. So we use lt 2 to check that's greater than 2.

Notes

Some things that could have been better for hgl in this challenge.

  • There should be a function lt2=lt 2 (and gt1, lt3 etc.). That would have saved a byte here.
  • (**) has the default precedence which although not causing any issues here, could probably be improved.
  • Variants of px and sx that give for example non-empty or strict prefixes / suffixes would probably be useful. If I had versionsa function that specifically gave non-empty and strict suffixes then I could just do ay**sw$sxs (where sxs is the imagined function) and check if any suffix is also a prefixfor 10 bytes.

Haskell + hgl, 13 bytes

cP$h_<*h'>~ʃ

If you can simply submit a parser object, then that can be 10 bytes:

h_<*h'>~ʃ

Explanation

  • h_ parses at least one thing off the front of a list (think .+ in regex).
  • h' parses any amount off the front of a list (think .* in regex).
  • ʃ is a function which takes an string and produces a parser which matches exactly that string.

We combine the two with <* which runs both sequentially giving the result of the first. Then we bind this to ʃ, so that the result of h_ is passed as the input to ʃ.

In do notation this would be

do x<-h_;h';ʃ x

Described in plain English this matches any string that contains the same non-empty section at both the start and end.

Non-parser, 17 15 bytes

The parsers are obviously the way to go for this challenge, but I thought I'd give it a go without them to see how good hgl does.

lt 2<(cn**sw)sx

Explanation

  • sx gets all prefixes of a list
  • sw checks if a particular list starts with another.
  • cn counts the number of elements that satisfy a predicate.
  • (**) is an infix for liftA2.

So altogether (cn**sw)sx counts the number of suffixes of the list are also prefixes.

Now, the empty string and the input string should always pass this test. So we want to test if there is another string which also is both a prefix and a suffix. So we use lt 2 to check that's greater than 2.

Notes

Some things that could have been better for hgl in this challenge.

  • There should be a function lt2=lt 2 (and gt1, lt3 etc.). That would have saved a byte here.
  • (**) has the default precedence which although not causing any issues here, could probably be improved.
  • Variants of px and sx that give for example non-empty or strict prefixes / suffixes would probably be useful. If I had versions that specifically gave non-empty and strict suffixes then I could just do ay**sw$sxs (where sxs is the imagined function) and check if any suffix is also a prefix.

Haskell + hgl, 13 bytes

cP$h_<*h'>~ʃ

If you can simply submit a parser object, then that can be 10 bytes:

h_<*h'>~ʃ

Explanation

  • h_ parses at least one thing off the front of a list (think .+ in regex).
  • h' parses any amount off the front of a list (think .* in regex).
  • ʃ is a function which takes an string and produces a parser which matches exactly that string.

We combine the two with <* which runs both sequentially giving the result of the first. Then we bind this to ʃ, so that the result of h_ is passed as the input to ʃ.

In do notation this would be

do x<-h_;h';ʃ x

Described in plain English this matches any string that contains the same non-empty section at both the start and end.

Non-parser, 17 15 bytes

The parsers are obviously the way to go for this challenge, but I thought I'd give it a go without them to see how good hgl does.

lt 2<(cn**sw)sx

Explanation

  • sx gets all prefixes of a list
  • sw checks if a particular list starts with another.
  • cn counts the number of elements that satisfy a predicate.
  • (**) is an infix for liftA2.

So altogether (cn**sw)sx counts the number of suffixes of the list are also prefixes.

Now, the empty string and the input string should always pass this test. So we want to test if there is another string which also is both a prefix and a suffix. So we use lt 2 to check that's greater than 2.

Notes

Some things that could have been better for hgl in this challenge.

  • There should be a function lt2=lt 2 (and gt1, lt3 etc.). That would have saved a byte here.
  • (**) has the default precedence which although not causing any issues here, could probably be improved.
  • Variants of px and sx that give for example non-empty or strict prefixes / suffixes would probably be useful. If I had a function that specifically gave non-empty and strict suffixes then I could just do ay**sw$sxs (where sxs is the imagined function) for 10 bytes.
edited body
Source Link
Wheat Wizard
  • 100k
  • 22
  • 282
  • 661

Haskell + hgl, 13 bytes

cP$h_<*h'>~ʃ

If you can simply submit a parser object, then that can be 10 bytes:

h_<*h'>~ʃ

Explanation

  • h_ parses at least one thing off the front of a list (think .+ in regex).
  • h' parses any amount off the front of a list (think .* in regex).
  • ʃ is a function which takes an string and produces a parser which matches exactly that string.

We combine the two with <* which runs both sequentially giving the result of the first. Then we bind this to ʃ, so that the result of h_ is passed as the input to ʃ.

In do notation this would be

do x<-h_;h';ʃ x

Described in plain English this matches any string that contains the same non-empty section at both the start and end.

Non-parser, 1717 15 bytes

The parsers are obviously the way to go for this challenge, but I thought I'd give it a go without them to see how good hgl does.

lt 2<l<2<(nx**pxcn**sw)sx

Explanation

  • sx gets all prefixes of a list
  • sw checks if a particular list starts with another.
  • cn counts the number of elements that satisfy a predicate.
  • (**) is an infix for liftA2.

px gets all prefixes of a list, So altogether sx gets all suffixes of a list. (nx**pxcn**sw)sx getscounts the intersectionnumber of the prefixes and the suffixes of athe list. So all strings that are bothalso prefixes and suffixes of the list.

Now, the empty string and the input string should always be inpass this resulttest. So we want to test if there is another string which also is both a prefix and a suffix. So we use l to get the length and lt 2 to check that's greater than 2.

Notes

Some things that could have been better for hgl in this challenge.

  • There should be a function lt2=lt 2 (and gt1, lt3 etc.). That would have saved a byte here.
  • (**) has the default precedence which although not causing any issues here, could probably be improved.
  • Variants of px and sx that give for example non-empty or strict prefixes / suffixes would probably be useful. If I had versions that specifically gave non-empty and strict prefixes / suffixes then I could usejust do øay**sw$sxs instead of (where lt 2<lsxs to save 4 bytesis the imagined function) and check if any suffix is also a prefix.

Haskell + hgl, 13 bytes

cP$h_<*h'>~ʃ

If you can simply submit a parser object, then that can be 10 bytes:

h_<*h'>~ʃ

Explanation

  • h_ parses at least one thing off the front of a list (think .+ in regex).
  • h' parses any amount off the front of a list (think .* in regex).
  • ʃ is a function which takes an string and produces a parser which matches exactly that string.

We combine the two with <* which runs both sequentially giving the result of the first. Then we bind this to ʃ, so that the result of h_ is passed as the input to ʃ.

In do notation this would be

do x<-h_;h';ʃ x

Described in plain English this matches any string that contains the same non-empty section at both the start and end.

Non-parser, 17 bytes

The parsers are obviously the way to go for this challenge, but I thought I'd give it a go without them to see how good hgl does.

lt 2<l<(nx**px)sx

Explanation

px gets all prefixes of a list, sx gets all suffixes of a list. (nx**px)sx gets the intersection of the prefixes and the suffixes of a list. So all strings that are both prefixes and suffixes of the list.

Now, the empty string and the input string should always be in this result. So we want to test if there is another string which also is both a prefix and a suffix. So we use l to get the length and lt 2 to check that's greater than 2.

Notes

Some things that could have been better for hgl in this challenge.

  • There should be a function lt2=lt 2 (and gt1, lt3 etc.). That would have saved a byte here.
  • (**) has the default precedence which although not causing any issues here, could probably be improved.
  • Variants of px and sx that give for example non-empty or strict prefixes / suffixes would probably be useful. If I had versions that specifically gave non-empty and strict prefixes / suffixes then I could use ø instead of lt 2<l to save 4 bytes.

Haskell + hgl, 13 bytes

cP$h_<*h'>~ʃ

If you can simply submit a parser object, then that can be 10 bytes:

h_<*h'>~ʃ

Explanation

  • h_ parses at least one thing off the front of a list (think .+ in regex).
  • h' parses any amount off the front of a list (think .* in regex).
  • ʃ is a function which takes an string and produces a parser which matches exactly that string.

We combine the two with <* which runs both sequentially giving the result of the first. Then we bind this to ʃ, so that the result of h_ is passed as the input to ʃ.

In do notation this would be

do x<-h_;h';ʃ x

Described in plain English this matches any string that contains the same non-empty section at both the start and end.

Non-parser, 17 15 bytes

The parsers are obviously the way to go for this challenge, but I thought I'd give it a go without them to see how good hgl does.

lt 2<(cn**sw)sx

Explanation

  • sx gets all prefixes of a list
  • sw checks if a particular list starts with another.
  • cn counts the number of elements that satisfy a predicate.
  • (**) is an infix for liftA2.

So altogether (cn**sw)sx counts the number of suffixes of the list are also prefixes.

Now, the empty string and the input string should always pass this test. So we want to test if there is another string which also is both a prefix and a suffix. So we use lt 2 to check that's greater than 2.

Notes

Some things that could have been better for hgl in this challenge.

  • There should be a function lt2=lt 2 (and gt1, lt3 etc.). That would have saved a byte here.
  • (**) has the default precedence which although not causing any issues here, could probably be improved.
  • Variants of px and sx that give for example non-empty or strict prefixes / suffixes would probably be useful. If I had versions that specifically gave non-empty and strict suffixes then I could just do ay**sw$sxs (where sxs is the imagined function) and check if any suffix is also a prefix.
edited body
Source Link
Wheat Wizard
  • 100k
  • 22
  • 282
  • 661
Loading
deleted 7 characters in body
Source Link
Wheat Wizard
  • 100k
  • 22
  • 282
  • 661
Loading
added 847 characters in body
Source Link
Wheat Wizard
  • 100k
  • 22
  • 282
  • 661
Loading
Source Link
Wheat Wizard
  • 100k
  • 22
  • 282
  • 661
Loading