haskal
2020-12-7 08:39:58

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
2020-12-7 14:09:52

@ben.knoble has joined the channel


caente
2020-12-7 15:42:42

@caente has left the channel


badkins
2020-12-7 21:56:24

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


badkins
2020-12-8 01:24:32

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.


badkins
2020-12-8 01:25:14

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


badkins
2020-12-8 01:27:18

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