aboutsummaryrefslogtreecommitdiff
path: root/2018/day2.p6
diff options
context:
space:
mode:
Diffstat (limited to '2018/day2.p6')
-rw-r--r--2018/day2.p643
1 files changed, 43 insertions, 0 deletions
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 <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);