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

50%
+0 −0
Challenges Cumulative Counts

Haskell + hgl, 10 bytes mpn$ce~<gj Attempt This Online! Explanation mpn map across all non-empty prefixes of the input ... ce count the number of elements in each prefix equal to ... g...

posted 1y ago by WheatWizard‭

Answer
#1: Initial revision by user avatar WheatWizard‭ · 2023-06-23T15:56:03Z (over 1 year ago)
# [Haskell](https://www.haskell.org) + [hgl](https://gitlab.com/wheatwizard/haskell-golfing-library), 10 bytes

```haskell
mpn$ce~<gj
````

[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8FNxczcgvyiEoXC0sSczLTM1BSFgKLUnNKUVC6oRMDS0pI0XYs1aba5BXkqyal1NulZEKGbrrmJmXkKtgop-VwKBUUKKgppCtGGOoY6RmBoCIbGOsaxCFljHXMdUx0THUugvDEQm-mYxUIMW7AAQgMA)

## Explanation

- `mpn` map across all non-empty prefixes of the input ...
- `ce` count the number of elements in each prefix equal to ...
- `gj` the last element of that prefix.

## Reflection

I'm happy with this.  It doesn't take any extra steps, and the glue is cheap.