
this is my first solution (~18 minutes): https://git.lain.faith/haskal/aoc2020/src/commit/3f4c2dea097bd5b305fd8af27a8e5d98e2283f0c/7.rkt this is my second solution (~ 2 hours): https://git.lain.faith/haskal/aoc2020/src/commit/bcce377a7dec35c1fed4d9b868fe5ef9f6ab0098/7.rkt second one took 2 hours because figuring out how graph-lib (do-dfs
) works for the first time was unexpectedly frustrating and at this point i want to improve the docs but i’m not entirely sure how i could make it easier

@ben.knoble has joined the channel

@caente has left the channel

The person in 2nd place for <https://adventofcode.com/|Advent of Code> wrote their own <https://github.com/betaveros/advent-of-code-golf–2020|golfing programming language> I think APL, J, etc. are envious :).

I saw <https://github.com/tckmn/polyaoc–2020/blob/master/07/rb/07.rb|a nice Ruby solution> for Day 7 from one of the people pretty high up on the leaderboard, so I made a Racket version based on some of the ideas. I’ll put it in a thread to avoid spoilers.

#lang racket
(require threading)
(define (part1 hsh bag)
(~> (hash->list hsh)
(filter (λ (l) (member bag (cdr l))) _)
(map (λ (l) (part1 hsh (car l))) _)
(foldl (λ (l result) (set-union result l)) (set bag) _)))
(~> (file->lines "day07.txt")
(map (curry regexp-match* #px"([a-z]+ [a-z]+)(?= bag)") _)
(make-immutable-hasheq _)
(part1 _ "shiny gold")
(set-count _)
(sub1 _))

The select
method for Hash returns a Hash, but the map
method on Hash returns a List, so in this case it will return a List of Sets which will then be folded in part1