aboutsummaryrefslogtreecommitdiff
path: root/2018/day2.p6
blob: 994502463d1728c68546f1d3a2d7c3e67eadfb2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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);