diff options
author | Matias Linares <matias.linares@comprandoengrupo.net> | 2019-12-10 13:07:59 -0300 |
---|---|---|
committer | Matias Linares <matias.linares@comprandoengrupo.net> | 2019-12-10 13:07:59 -0300 |
commit | cb183143844f52159ace47ad6aa8bdbe5524e656 (patch) | |
tree | 87c51e0989507201eefe5224bd2a71e5797dfd77 /lib | |
parent | 8f35c2dc6516303ae0786d08cc7912ccb8218f78 (diff) | |
download | advent-of-code-2019-master.tar.gz |
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AdventOfCode/Day3.rakumod~ | 3 | ||||
-rw-r--r-- | lib/AdventOfCode/Utils.rakumod~ | 64 |
2 files changed, 0 insertions, 67 deletions
diff --git a/lib/AdventOfCode/Day3.rakumod~ b/lib/AdventOfCode/Day3.rakumod~ deleted file mode 100644 index 0952835..0000000 --- a/lib/AdventOfCode/Day3.rakumod~ +++ /dev/null @@ -1,3 +0,0 @@ -sub MAIN() { - say "a" -} diff --git a/lib/AdventOfCode/Utils.rakumod~ b/lib/AdventOfCode/Utils.rakumod~ deleted file mode 100644 index d55a045..0000000 --- a/lib/AdventOfCode/Utils.rakumod~ +++ /dev/null @@ -1,64 +0,0 @@ -class Point { - has $.x = 0; - has $.y = 0; - - method Str(--> Str) { - "Point ($.x, $.y)" - } -} - -class Line { - has Point $.p; - has Point $.q; -} - -sub intersection(Line $l1, Line $l2) is export { - my $a1 = $l1.q.y - $l1.p.y; - my $b1 = $l1.p.x - $l1.q.x; - my $c1 = $a1 * $l1.p.x + $b1 * $l1.p.y; - - my $a2 = $l2.q.y - $l2.p.y; - my $b2 = $l2.p.x - $l2.q.x; - my $c2 = $a2 * $l2.p.x + $b2 * $l2.p.y; - - my $delta = $a1 * $b2 - $a2 * $b1; - - return Point.new( - :x(($b2 * $c1 - $b1 * $c2) / $delta), - :y(($a1 * $c2 - $a2 * $c1) / $delta) - ) -} - -sub manhattan-distance(Point $p, Point $q) { - abs($p.x - $q.x) + abs($p.y - $q.y) -} - - -class Wire { - has Point @.points; - - submethod new(Str $input) { - my @movements = $input.split(','); - my @points; - - for @movements -> $move { - if $move ~~ /$<direction> = [ <[ UDLR ]> ] $<size> = [ \d+]/ { - my $x = 0; - my $y = 0; - given $<direction> { - when "U" { $y += $<size>.Int } - when "D" { $y += -$<size>.Int } - when "L" { $x += -$<size>.Int } - when "R" { $x += $<size>.Int } - } - @points.append: Point.new(:$x, :$y); - } - } - - self.bless(:@points); - } - - method segments { - @.points[0..^*-1] Z @.points[1..*] - } -} |