Skip to main content
added 212 characters in body
Source Link
Wheat Wizard
  • 102.8k
  • 23
  • 299
  • 697

Haskell + hgl, 18 bytes

or<xQ iw<sj<sYe"|" 

Explanation

  • sYe"|" split along |s
  • sj sort by ascending length
  • xQ iw for each pair of items give whether the first is an infix of the second.
  • or or over the results

We need to sort the list because xQ compares only pairs where the first item comes before the second. Since to be an infix a string must be shorter, we sort by length.

Reflection

It feels like we just miss a much shorter answer in a bunch of ways.

  • There should be a reflexive version of iw. If this were the case we could really shorten things. This would save us from having to sort the list.
  • There should at least be a function to "reflexivize" an operator, so that if this happens again where I want a reflexive version of an operator I can make it relatively cheaply. This probably wouldn't save bytes here, but there might not be the same sorting trick in the future.
  • xQ takes all pairs where the first item appears before the second and applies a function. If there was a function which takes all pairs other than those on the diagonal that would also save us from having to sort the list.
  • There should be a version of xQ which automatically combines the results. There's already epa for pa in the same module, so this seems like an oversight.
  • I could probably have versions of sYe preloaded with various character classes. For this both "split along non-alphabetic" and "split along symbols" would work, and are probably sufficiently useful to justify their creation.
  • There should be a function to count the number of times something appears as an infix. Another way to solve this problem should be to ask whether any of the words appears more than once in the original regex.

Haskell + hgl, 18 bytes

or<xQ iw<sj<sYe"|" 

Explanation

  • sYe"|" split along |s
  • sj sort by ascending length
  • xQ iw for each pair of items give whether the first is an infix of the second.
  • or or over the results

We need to sort the list because xQ compares only pairs where the first item comes before the second. Since to be an infix a string must be shorter, we sort by length.

Reflection

It feels like we just miss a much shorter answer in a bunch of ways.

  • There should be a reflexive version of iw. If this were the case we could really shorten things. This would save us from having to sort the list.
  • There should at least be a function to "reflexivize" an operator, so that if this happens again where I want a reflexive version of an operator I can make it relatively cheaply. This probably wouldn't save bytes here, but there might not be the same sorting trick in the future.
  • xQ takes all pairs where the first item appears before the second and applies a function. If there was a function which takes all pairs other than those on the diagonal that would also save us from having to sort the list.
  • There should be a version of xQ which automatically combines the results. There's already epa for pa in the same module, so this seems like an oversight.
  • I could probably have versions of sYe preloaded with various character classes. For this both "split along non-alphabetic" and "split along symbols" would work, and are probably sufficiently useful to justify their creation.

Haskell + hgl, 18 bytes

or<xQ iw<sj<sYe"|" 

Explanation

  • sYe"|" split along |s
  • sj sort by ascending length
  • xQ iw for each pair of items give whether the first is an infix of the second.
  • or or over the results

We need to sort the list because xQ compares only pairs where the first item comes before the second. Since to be an infix a string must be shorter, we sort by length.

Reflection

It feels like we just miss a much shorter answer in a bunch of ways.

  • There should be a reflexive version of iw. If this were the case we could really shorten things. This would save us from having to sort the list.
  • There should at least be a function to "reflexivize" an operator, so that if this happens again where I want a reflexive version of an operator I can make it relatively cheaply. This probably wouldn't save bytes here, but there might not be the same sorting trick in the future.
  • xQ takes all pairs where the first item appears before the second and applies a function. If there was a function which takes all pairs other than those on the diagonal that would also save us from having to sort the list.
  • There should be a version of xQ which automatically combines the results. There's already epa for pa in the same module, so this seems like an oversight.
  • I could probably have versions of sYe preloaded with various character classes. For this both "split along non-alphabetic" and "split along symbols" would work, and are probably sufficiently useful to justify their creation.
  • There should be a function to count the number of times something appears as an infix. Another way to solve this problem should be to ask whether any of the words appears more than once in the original regex.
Source Link
Wheat Wizard
  • 102.8k
  • 23
  • 299
  • 697

Haskell + hgl, 18 bytes

or<xQ iw<sj<sYe"|" 

Explanation

  • sYe"|" split along |s
  • sj sort by ascending length
  • xQ iw for each pair of items give whether the first is an infix of the second.
  • or or over the results

We need to sort the list because xQ compares only pairs where the first item comes before the second. Since to be an infix a string must be shorter, we sort by length.

Reflection

It feels like we just miss a much shorter answer in a bunch of ways.

  • There should be a reflexive version of iw. If this were the case we could really shorten things. This would save us from having to sort the list.
  • There should at least be a function to "reflexivize" an operator, so that if this happens again where I want a reflexive version of an operator I can make it relatively cheaply. This probably wouldn't save bytes here, but there might not be the same sorting trick in the future.
  • xQ takes all pairs where the first item appears before the second and applies a function. If there was a function which takes all pairs other than those on the diagonal that would also save us from having to sort the list.
  • There should be a version of xQ which automatically combines the results. There's already epa for pa in the same module, so this seems like an oversight.
  • I could probably have versions of sYe preloaded with various character classes. For this both "split along non-alphabetic" and "split along symbols" would work, and are probably sufficiently useful to justify their creation.