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/day2.p6 | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 2018/day2.p6 (limited to '2018/day2.p6') diff --git a/2018/day2.p6 b/2018/day2.p6 new file mode 100644 index 0000000..9945024 --- /dev/null +++ b/2018/day2.p6 @@ -0,0 +1,43 @@ +use v6; +use lib ; + +use Utils; + +sub day2-pt1(@input) { + my %count = "2" => 0, "3" => 0; + for @input -> $line { + my $bag = bag $line.comb; + %count<2>++ if $bag.first(*.value == 2); + %count<3>++ if $bag.first(*.value == 3); + } + say %count<2> * %count<3>; +} + +sub wolo(@params) { + my \s = @params[0]; + my \t = @params[1]; + my $ld = levenshtein(s, t); + say "Got $ld for {s} and {t}"; + return (s, t, $ld); +} + +sub wole(@params) { + my $s = @params[0]; + my $t = @params[1]; + + my $cmp = ($s.comb Z $t.comb).grep({ $_[0] ne $_[1] }).elems; + if $cmp == 1 { + say "Got $cmp for $s and $t" + } + return $s, $t, $cmp +} + +sub day2-pt2(@input) { + my ($a, $b, $c) = @input.combinations(2).race.map(&wole).first(-> @vals { @vals[2] == 1 }); + say $a.comb Z $b.comb; + say ($a.comb Z $b.comb).grep({ $_[0] eq $_[1] }).map(*.first).join +} + +my @input = parse-input; +day2-pt1(@input); +day2-pt2(@input); -- cgit v1.2.3-70-g09d2