about summary refs log tree commit diff
path: root/aoc/2021/03/part-two.raku
blob: 71464a246eaa12080ee9618beb6193482b01e803 (plain) (blame)
1
2
3
4
5
6
7
8
sub filter(&op, @report, $column=0) {
    return parse-base @report[0].join, 2 unless @report.elems > 1;
    my $common = ([+] map *[$column], @report) > (@report.elems - 1) div 2;
    filter &op, (grep { op $_[$column], $common }, @report), $column + 1
}

my $input = map *.comb, words slurp 'input';
put [*] map { filter $_, $input }, (&infix:<==>, &infix:<!=>)