Advent of Code 2020: Haskell Edition

Hi all,

I thought it would be fun to share my solutions so far for Advent of Code 2020, and invite anyone else to do the same!
I got this idea from the PureScript Discourse site, but I’m one of the rare folks out there who has significantly more PureScript experience than Haskell experience and I wanted to focus more on my Haskell skills right now. Hopefully we can all learn from each other by seeing how we solve some fun puzzles in different ways!

4 Likes

I’m also having fun with AOC2020, I’m solving it pretty sloppily but I wouldn’t mind publishing my solutions if it’s interesting for anyone.

btw ntwilson, I’ve noticed you defined # and <#> operators, note that in haskell these are & and <&> :slight_smile:

1 Like

Thanks gilmi,
I pulled those from PureScript, honestly :stuck_out_tongue:.
I might be missing something, but I think # and <#> are the flipped versions of $ and <$>, in the event that any expressions read easier “inside out” instead of “outside in” (when reading left-to-right).
I’d definitely love to see your solutions even if sloppy, because I bet you’ve got a lot of tricks that I’m not familiar with!

I figured :slight_smile: I’m just saying that the equivalent names for PureScript’s # and <#> in Haskell are & and <&>.

I uploaded my solutions up until now to this repo: https://gitlab.com/gilmi/aoc2020

4 Likes

I knew there was a good reason to post my solutions on discourse. Learning things already. Thanks gilmi!
(I totally misread your original response and thought you just referred me to $ and <$>)

2 Likes

Always nice to see other people’s solutions!

Since Haskell is my day job, I decided to solve the Advent of Code puzzles with Elm this year. You can see my solutions here: https://github.com/tfausak/advent-of-code-2020

2 Likes

I feel like today’s 2nd puzzle really played to one of Haskell’s strengths :slight_smile:
Uploaded my solution to my repo.

1 Like

Well to my shame, I might be the only one still doing Advent of Code puzzles here towards the end of January, but I thought the puzzle for day 14 was able to use Haskell’s strengths in a pretty cool way.
SPOILERS for anyone who’s even further behind than I am :wink:
In part 1 you apply a bit mask to some binary string. NP. In part 2, the bit mask is modified so that some bits get set to either 0 or 1, and you have to calculate all possible permutations. Oh okay, so I can just wrap each bit in a list, and then slap sequence in front, and I’ve got all the permutations.
I get the impression that in your “traditional” language, a change in requirements like that would mean an almost total rewrite, and in Haskell, it was a 5 minute modification, with no added lines of code (well, in my case 1 added line because I wanted an additional type annotation)