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/day2.p6 | |
parent | 5fa17cd54a1170449a91da48a2fe88a99349daa2 (diff) | |
download | advent-of-code-a0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e.tar.gz |
Add 2018 and 2017
Diffstat (limited to '2018/day2.p6')
-rw-r--r-- | 2018/day2.p6 | 43 |
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); |