about summary refs log tree commit diff
path: root/aoc/2021/03/part-two.raku
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-12-05 15:18:59 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-12-05 15:18:59 +0700
commit85bd7ec1bd9cdc7ec53692fce5cae3118b7357a0 (patch)
tree1880d6822b4c1e6d978abb0dda073dd42755efad /aoc/2021/03/part-two.raku
parent48f468b9b8a3f909b60399e277405b9723b8643a (diff)
downloadcp-85bd7ec1bd9cdc7ec53692fce5cae3118b7357a0.tar.gz
[aoc] Add first five/fifth
Diffstat (limited to 'aoc/2021/03/part-two.raku')
-rw-r--r--aoc/2021/03/part-two.raku8
1 files changed, 8 insertions, 0 deletions
diff --git a/aoc/2021/03/part-two.raku b/aoc/2021/03/part-two.raku
new file mode 100644
index 0000000..71464a2
--- /dev/null
+++ b/aoc/2021/03/part-two.raku
@@ -0,0 +1,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:<!=>)