From a0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 5 Dec 2020 10:55:56 -0300 Subject: Add 2018 and 2017 --- 2018/day3.p6 | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 2018/day3.p6 (limited to '2018/day3.p6') 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 ; +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, + top => $m, + width => $m, + height => $m +)}); + + 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; +} -- cgit v1.2.3-70-g09d2