diff options
author | Matias Linares <matiaslina@gmail.com> | 2020-12-05 10:55:56 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2020-12-05 10:55:56 -0300 |
commit | a0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e (patch) | |
tree | a663ee4f6a427e98db0878ca539c9288bfbc70d0 /2018/day3.p6 | |
parent | 5fa17cd54a1170449a91da48a2fe88a99349daa2 (diff) | |
download | advent-of-code-a0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e.tar.gz |
Add 2018 and 2017
Diffstat (limited to '2018/day3.p6')
-rw-r--r-- | 2018/day3.p6 | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/2018/day3.p6 b/2018/day3.p6 new file mode 100644 index 0000000..ce9ae2d --- /dev/null +++ b/2018/day3.p6 @@ -0,0 +1,60 @@ +use lib <lib>; +use Utils; + +class Point { has $.x; has $.y; method gist { "{$.x}×{$.y}" }} + +class Fabric { + has $.left; + has $.top; + has $.width; + has $.height; + + method points { + gather { + my @rx = $.left ..^ ($.left+$.width); + my @ry = ($.top) ..^ ($.top+$.height); + for @rx -> $x { + for @ry -> $y { + take "$x,$y"; + } + } + } + } +} + +sub infix:<ð>(Fabric $f1, Fabric $f2) { + say $f1.points; + say $f2.points; + say ''; + my $a = set($f1.points); + my $b = set($f2.points); + say $a (&) $b; +} + +sub pt1($data --> Int) { + my @fabric = $data.lines.map({ +my $m = Day3.parse($_); +Fabric.new( + left => $m<position><left>, + top => $m<position><top>, + width => $m<size><width>, + height => $m<size><height> +)}); + + for @fabric.combinations(2) -> @f { + @f[0] ð @f[1] + } + + return 0; +} + +sub MAIN("test") { + my @data = q:to/E/; + #1 @ 1,3: 4x4 + #2 @ 3,1: 4x4 + #3 @ 5,5: 2x2 + E + my $sq = pt1(@data); + + die "Got $sq instead 4" if $sq != 4; +} |