Raku: Advent of Code 2020 - Day Seven
Raku solution for Day 7 of Advent of Code. Commentary follows the code... If you enjoy it or can offer improvements, please leave a comment. #!/usr/bin/env raku use v6.d ; grammar Baggage { rule TOP { < rule > + } rule rule { < color > 'bags contain' < contents > '.' } rule contents { 'no other bags' | [ < quantity > < color > < . bag > ] + % ',' } token color { \w + \W + \w + } token quantity { \d + } token bag { 'bag' | 'bags' } } class BaggageActions { has $.inside = {}; has $.outside = {}; method rule ( $/ ) { return if 'no other bags' eq ~ $< contents > ; my $outer = ~ $< color > ; my $inner = %( $< contents > . < color > . map ({ ~ $_ }) . List Z=> $< contents > . < quantity > . map ({ + $_ }) . List ) ; $!inside { $outer } = $inner ; for $inner . pa...