Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Efficient censorship

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...

posted 1y ago by WheatWizard‭  ·  edited 1y ago by WheatWizard‭

Answer
#2: Post edited by user avatar WheatWizard‭ · 2023-06-20T13:16:56Z (over 1 year ago)
  • # [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 by user avatar WheatWizard‭ · 2023-06-20T13:16:18Z (over 1 year ago)
# [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.