Post History
Haskell + hgl, 14 bytes xBl<<ss><fn<iw Attempt This Online! Explanation ss gets all substrings of the input fn filters out the substrings that don't ... iw checks if the fo...
Answer
#2: Post edited
- # [Haskell](https://www.haskell.org) + [hgl](https://gitlab.com/wheatwizard/haskell-golfing-library), 14 bytes
- ```haskell
- xBl<<ss><fn<iw
- ````
- [Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8FNxczcgvyiEoXC0sSczLTM1BSFgKLUnNKUVC6oRMDS0pI0XYsNabYVTjk2NsXFdjZpeTaZ5RDhm7tyEzPzFGwVUvK5FBRy4xUKgoG0QrRCmoJScmKJEpDMAFIgMR2EWGoxkM5IRQjnAwUz8nPzc_LTK9EVJwMpJBMSkxKTgKKJIDoJzMGQQhdOTARrgAKwRCyQgPhgwQIIDQA)
- ## Explanation
- * `ss` gets all substrings of the input
* `fn` filters out the substrings that ..- * `iw` checks if the forbidden word is a contiguous substring
- * `xBl` gets the largest result
- ## Reflection
- There are a couple things that could be improved.
- My first thought when writing this was: "I will list the substrings and just get the first one that satisfies the predicate", however there are two issues with this:
- - `ss` does not output the substrings in a length based order. The order honestly seems sort of random. According to the docs "Items are ordered by the index of their final element with the empty list coming first." Which is true, however I fail to imagine a scenario in which that is the order you want to get the ouputs. I can imagine a scenario in which you want the longer substrings earlier (this exact challenge), so it should probably be changed.
- - The function `g1` which gives the first element satisfying a predicate, returns a `Maybe'`. This makes sense, in general there might not be an element satisfying the predicate. However it is annoying. In this case I know that there always is at least one. There should be a version of `g1` which is unsafe in this regard. (There's also a typo in `g1`s documentation)
- Now moving onto my actual answer, I see a couple of functions I use which could be combined into reusable functions:
- - `xBl` and `fn`/`fl` could be combined into a two functions "Longest such that" and "Longest such that not".
- - The above function could also be combined with `ss` to give two functions "Longest substring such that" and "Longest substring such that not", as these are both common enough set ups for code golf challenges, that they will likely come up again.
- # [Haskell](https://www.haskell.org) + [hgl](https://gitlab.com/wheatwizard/haskell-golfing-library), 14 bytes
- ```haskell
- xBl<<ss><fn<iw
- ````
- [Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8FNxczcgvyiEoXC0sSczLTM1BSFgKLUnNKUVC6oRMDS0pI0XYsNabYVTjk2NsXFdjZpeTaZ5RDhm7tyEzPzFGwVUvK5FBRy4xUKgoG0QrRCmoJScmKJEpDMAFIgMR2EWGoxkM5IRQjnAwUz8nPzc_LTK9EVJwMpJBMSkxKTgKKJIDoJzMGQQhdOTARrgAKwRCyQgPhgwQIIDQA)
- ## Explanation
- * `ss` gets all substrings of the input
- * `fn` filters out the substrings that don't ...
- * `iw` checks if the forbidden word is a contiguous substring
- * `xBl` gets the largest result
- ## Reflection
- There are a couple things that could be improved.
- My first thought when writing this was: "I will list the substrings and just get the first one that satisfies the predicate", however there are two issues with this:
- - `ss` does not output the substrings in a length based order. The order honestly seems sort of random. According to the docs "Items are ordered by the index of their final element with the empty list coming first." Which is true, however I fail to imagine a scenario in which that is the order you want to get the ouputs. I can imagine a scenario in which you want the longer substrings earlier (this exact challenge), so it should probably be changed.
- - The function `g1` which gives the first element satisfying a predicate, returns a `Maybe'`. This makes sense, in general there might not be an element satisfying the predicate. However it is annoying. In this case I know that there always is at least one. There should be a version of `g1` which is unsafe in this regard. (There's also a typo in `g1`s documentation)
- Now moving onto my actual answer, I see a couple of functions I use which could be combined into reusable functions:
- - `xBl` and `fn`/`fl` could be combined into a two functions "Longest such that" and "Longest such that not".
- - The above function could also be combined with `ss` to give two functions "Longest substring such that" and "Longest substring such that not", as these are both common enough set ups for code golf challenges, that they will likely come up again.
#1: Initial revision
# [Haskell](https://www.haskell.org) + [hgl](https://gitlab.com/wheatwizard/haskell-golfing-library), 14 bytes ```haskell xBl<<ss><fn<iw ```` [Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8FNxczcgvyiEoXC0sSczLTM1BSFgKLUnNKUVC6oRMDS0pI0XYsNabYVTjk2NsXFdjZpeTaZ5RDhm7tyEzPzFGwVUvK5FBRy4xUKgoG0QrRCmoJScmKJEpDMAFIgMR2EWGoxkM5IRQjnAwUz8nPzc_LTK9EVJwMpJBMSkxKTgKKJIDoJzMGQQhdOTARrgAKwRCyQgPhgwQIIDQA) ## Explanation * `ss` gets all substrings of the input * `fn` filters out the substrings that .. * `iw` checks if the forbidden word is a contiguous substring * `xBl` gets the largest result ## Reflection There are a couple things that could be improved. My first thought when writing this was: "I will list the substrings and just get the first one that satisfies the predicate", however there are two issues with this: - `ss` does not output the substrings in a length based order. The order honestly seems sort of random. According to the docs "Items are ordered by the index of their final element with the empty list coming first." Which is true, however I fail to imagine a scenario in which that is the order you want to get the ouputs. I can imagine a scenario in which you want the longer substrings earlier (this exact challenge), so it should probably be changed. - The function `g1` which gives the first element satisfying a predicate, returns a `Maybe'`. This makes sense, in general there might not be an element satisfying the predicate. However it is annoying. In this case I know that there always is at least one. There should be a version of `g1` which is unsafe in this regard. (There's also a typo in `g1`s documentation) Now moving onto my actual answer, I see a couple of functions I use which could be combined into reusable functions: - `xBl` and `fn`/`fl` could be combined into a two functions "Longest such that" and "Longest such that not". - The above function could also be combined with `ss` to give two functions "Longest substring such that" and "Longest substring such that not", as these are both common enough set ups for code golf challenges, that they will likely come up again.