Code for the Advent of Code event
aoc
advent-of-code
1#!/usr/bin/env perl6
2use v6;
3
4my %coords is default(Array);
5
6grammar AoC::Input {
7 token TOP { [ <entry> <.ws>? ]+ }
8 token entry {
9 '#' <id> <.ws> '@' <.ws> <position> ':' <.ws> <size>
10 {
11 for ^$<size><width>.made -> $xo {
12 for ^$<size><height>.made -> $yo {
13 my $x = $<position><x> + $xo;
14 my $y = $<position><y> + $yo;
15 %coords{"$x,$y"}.push: $<id>.made;
16 }
17 }
18 }
19 }
20 token id { \d+ { make +$/ } }
21 token position { $<x>=<num> ',' $<y>=<num> }
22 token size { $<width>=<num> x $<height>=<num> }
23 token num { \d+ { make +$/ } }
24}
25
26my $matches = AoC::Input.parsefile('input.txt');
27say "Part 1: {%coords.values.grep({ $_ > 1 }).elems}";